Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Slick slider replace dots with numbers

I'm trying to replace Slick slider / carousel pagination with numbers instead of dots. I have the project setup in js fiddle and I have have a custom function that displays the current slide count of a total of 6. I currently just have '1' replacing the dots but I would like to have the numbers represent the total number of slides.

JS Fiddle Demo

HTML

<section class="slider">
 <div>slide1</div>
 <div>slide2</div>
 <div>slide3</div>
 <div>slide4</div>
 <div>slide5</div>
 <div>slide6</div>
</section>

<span class="pagingInfo"></span>

Javascript

$(".slider").slick({
autoplay: true,
dots: true,
customPaging : function(slider, i) {
var thumb = $(slider.$slides[i]).data();
return '<a>1</a>';
},
responsive: [{ 
    breakpoint: 500,
    settings: {
        dots: false,
        arrows: false,
        infinite: false,
        slidesToShow: 2,
        slidesToScroll: 2
    } 
}]
});
like image 531
M1lls Avatar asked Jan 07 '16 16:01

M1lls


1 Answers

If i catch your meaning, Change this line:

return '<a>1</a>';

to this:

return '<a>'+i+'</a>';

or

return '<a>'+(i+1)+'</a>';

depending on where you want your index to start.

Here is your updated fiddle: https://jsfiddle.net/rLLvvpcm/5/

like image 188
IanGabes Avatar answered Sep 18 '22 05:09

IanGabes