Next, we want to set up the function that will create the next button, previous button, and pagination buttons and makes them work.
The jCarousel plugin provides a key called
initCallback
that will allow us to pass in the name of a function that should be called when the carousel is created. Let's get started by creating an empty function and calling it:var slider = $('#featured-carousel'); function carouselInit(carousel) { // Our function goes here } $(document).ready(function(){ slider.jcarousel({ scroll: 1, buttonNextHTML: null, buttonPrevHTML: null, initCallback: carouselInit }); });
Whatever actions we write inside of our
carouselInit()
function, it will be executed when the carousel is initialized or set up. Since any page numbers and previous and next buttons would only be functional if JavaScript is enabled, we want to create those buttons dynamically with JavaScript rather than coding them in our HTML. Let's take...