Slick Slider 在开始时转到第 n 个滑块

2022-01-24 00:00:00 slider javascript

我想使用 Slick Slider 从第 20 张幻灯片开始.我的代码是:

I want to use Slick Slider to start form 20th slide. My code is:

<script>
$(document).ready(function(){
$('.timeline-items').slick({
   slidesToShow: 5,
   slidesToScroll: 4,
   dots:true,
   arrows:true,
   infinite:false,
   autoplay: true,
   autoplaySpeed: 4500
});
$('.timeline-items').slickGoTo(20, false);
});
</script>

Slider 触发 OK(.slick 函数启动),但随后我得到:

Slider fires OK (.slick functions starts), but then i got:

Uncaught TypeError: $(...).slickGoTo is not a function

我做错了什么?

来自文档:

slickGoTo
int : slide number, boolean: dont animate 
Navigates to a slide by index

推荐答案

          $(function() {

                var tiSlick = $('.timeline-items').slick({
                              slidesToShow: 5,
                              slidesToScroll: 4,
                              dots:true,
                              arrows:true,
                              infinite:false,
                              autoplay: true,
                              autoplaySpeed: 4500
             });
             tiSlick.on('init', function(event, slick) {
             tiSlick.slick('slickGoTo', 20);
        });
    });

相关文章