Custom CMS Slider

After seeing @Maximosaurus create a CMS slider in Webflow with no code, I decided to attempt taking it a few steps further using custom code. It is dynamic, adding and removing slides automatically as Collection Items are added and removed. Styles can easily be updated in the editor without digging in the code, with all item states shown in the CMS for easy editing (the code replaces them in the live version).

The design includes arrows that respond based on first/last slide (in this case showing a different style when the ends are reached), and the nav bubbles function with the capability of numbers. No looping yet, but hope to add soon! Download this image via the link below for a breakdown of how to re-create this in a new document. And don't forget to copy the custom code from the "before </body>" section under page settings into your Webflow project!

Download Reference

<!-- Before /body -->
<script >
/*  Left/Right Arrow Styling  */
function leftArrowHide() {
   $("#left-arrow").removeClass('arrow-box').addClass('arrow-end');
}

function leftArrowShow() {
   $("#left-arrow").removeClass('arrow-end').addClass('arrow-box');
}

function rightArrowHide() {
   $("#right-arrow").removeClass('arrow-box').addClass('arrow-end');
}

function rightArrowShow() {
   $("#right-arrow").removeClass('arrow-end').addClass('arrow-box');
}
/*  Hide the CMS nav dots used for styling
and set the arrows to default styles for Slide 1  */
$('.navdot').hide();
rightArrowShow();
leftArrowHide();
/*  Generate nav dots for each CMS slide  */
var slideval = 0;
var cmscount = $("#slides").children().length;
var countconverted = (cmscount - 1) * -100;
for (i = 0; i < cmscount; i++) {
   var container = document.getElementById('#nav');
   var div = document.createElement("div");
   div.className = 'navdot';
   div.id = 'slide' + i;
   div.className += ' generated';
   var slidenumber = document.createElement("div");
   slidenumber.innerHTML = i + 1;
   slidenumber.className = 'navdot-number';
   div.append(slidenumber);
   document.getElementById('nav').append(div);
}

/*  Activate the generated nav dot for Slide 1. */
$("#slide0").addClass("selected");

/*  Click detection for nav dots. Activate the corresponding slide
and update the left/right arrows if on the first or last slide  */
$(".navdot").click(function() {
   $(".navdot").removeClass("selected");
   $(this).addClass("selected");
   var slide = $(this).attr('id');
   var num = slide.replace('slide', '');
   slide = parseInt(num);
   var multiplier = slide * -100;
   slideval = multiplier;
   if (slide == 0) {
       leftArrowHide();
       rightArrowShow();
   } else if (slide == cmscount - 1) {
       rightArrowHide();
       leftArrowShow();
   } else {
       leftArrowShow();
       rightArrowShow();
   }
   moveSlides(slideval);
   $('#animationTrigger').click();
});

/*  Right Arrow click detection and actions. */
$("#right-arrow").click(function() {
   if (slideval > countconverted) {
       leftArrowShow();
       slideval += -100;
       moveSlides(slideval);
       updatenav();
       $('#animationTrigger').click();
       if (slideval == countconverted) {
           rightArrowHide();
       }
   }
});
/*  Left Arrow click detection and actions. */
$("#left-arrow").click(function() {
   if (slideval < 0) {
       rightArrowShow();
       slideval += 100;
       moveSlides(slideval);
       updatenav();
       $('#animationTrigger').click();
       if (slideval == 0) {
           leftArrowHide();
       }
   }
});
/*  Function called on by arrow and nav dot clicks to move to
the selected slide  */
function moveSlides(measurement) {
   $('#slides').css({
       '-webkit-transform': 'translateX(' + slideval + '%)',
       '-moz-transform': 'translateX(' + slideval + '%)',
       '-ms-transform': 'translateX(' + slideval + '%)',
       '-o-transform': 'translateX(' + slideval + '%)',
       'transform': 'translateX(' + slideval + '%)'
   });
}
/*  Update nav dots so that the active dot corresponds to the
active slide  */
function updatenav() {
   $(".navdot").removeClass("selected");
   var slides = $('.generated');
   for (i = 0; i < slides.length; i++) {
       var slide = slides[i].id;
       var num = slide.replace('slide', '');
       slide = parseInt(num);
       var multiplier = slide * -100;
       if (multiplier == slideval) {
           $("#slide" + i).addClass("selected");
       }
   }
}
</script>

Custom Code

Copy the code on the left into the custom code settings on the page (in the "before /body" zone) to use the slider. Then create and style elements on the page using the reference guide from slide 1.

As of right now, only one slider can be on a page at a time. The slider doesn't currently loop, and swipe gestures aren't yet supported. Hope to add new features soon!

Debitis Et Voluptas Rerum

Est aliquid et rerum quia minus voluptatem voluptatem eius. Velit hic pariatur eius non itaque doloremque accusantium. Est facilis dolores quos aut delectus nisi hic tenetur. Harum et asperiores.

Velit ullam ut doloremque iste facere vitae repellat tenetur. Sit debitis maxime modi nemo iur

Molestiae molestiae

Voluptates Atque Voluptatum Quod

Qui doloremque eum et commodi. Reprehenderit quis qui omnis eos mollitia dolores dicta. Eos molestiae ab et.

Iure in provident. Et sapiente enim suscipit rerum voluptatem reprehenderit tempore. Repudiandae mollitia et. Sapiente porro numquam iste in facilis aspernatur delen

Deleniti iste

Doloremque

Odit dignissimos temporibus perspiciatis nihil et eum. Sit ut in aut atque voluptas asperiores voluptatem in. Odio magni accusamus dignissimos ad. Voluptatem quis rerum qui.

Dicta quis quam aliquam voluptas rerum voluptatem non. Deserunt perferendis illum omnis. Eum aut ut aut itaque vel recusandae

Non aperiam

Qui Facere Consequuntur

Officia et occaecati nam enim sequi non corrupti. Rem magnam molestiae saepe occaecati qui nemo fugiat nemo ipsa. Autem sint autem.

Repudiandae consequatur unde sit itaque expedita sit maxime. Tempore rerum qui nam eum nihil optio tempore. Nihil doloremque beatae cumque. Quis odio aut

Fugit magnam et

Aliquam Dolor Fugiat

Architecto placeat consequuntur ab enim et eius in explicabo eaque. Et et explicabo

In nulla consequatur

Voluptas Nihil

Commodi deleniti quis quibusdam ullam cupiditate porro reprehenderit in modi. Ab repudiandae consequatur fugit voluptatem id modi ea et qui. Voluptate dolorum non. Excepturi aut voluptatem tempore.


Autem placeat ipsa. Deleniti deleniti delectus molestiae est velit sit. Aut ut doloremqu.

Sit distinctio qui