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

时间:2015-12-09 10:41:41

标签: javascript slider

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

<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>

滑块触发OK(.slick函数启动),但后来我得到了:

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

我做错了什么?

来自文档:

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

1 个答案:

答案 0 :(得分:0)

          $(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);
        });
    });