上一张幻灯片放映警报中的slick.js [英] slick.js on last slide show alert

查看:118
本文介绍了上一张幻灯片放映警报中的slick.js的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用slick.js http://kenwheeler.github.io/slick/浏览一些幻灯片,最后一张幻灯片应切换警报.

I'm using slick.js http://kenwheeler.github.io/slick/ to run through some slides, the last of which should toggle an alert.

经过一番网上探索后,意识到无需硬编码幻灯片数量(并且已经看到以下解决方案: 滑动式传送带.想要自动播放一次幻灯片并停止播放),我有以下代码:

After some ferreting around online and realizing that this should work without having to hard code the number of slides (and having seen this solution: Slick carousel. Want autoplay to play the slides once and stop ), I've got the following code:

$(document).ready(function(){
          var item_length = $('.slider > div').length - 1;
          $('.slider').slick({
            appendArrows : '.arrow-holder',
            adaptiveHeight : true,
            infinite : false,
            onAfterChange: function(){
                if( item_length == slider.slickCurrentSlide() ){
                    alert("Slide 2");
                };
            }
          }); 
        });

不幸的是,当我到达最后一张幻灯片时,什么也没有发生.即使在考虑到零索引的情况下,我也不会在最后一个数字中进行硬编码.

Unfortunately, nothing happens when I reach the last slide. Nor does it seem to if I do hard code in the last number, even taking into account the zero indexing.

控制台中没有错误或警告,因此我正在努力寻找解决问题的方法.

I have no errors or warnings in the console, so am struggling to work out how to figure out the problem.

推荐答案

您的onAfterChange函数缺少滑动所需的输入. 这段代码应该解决它:

Your onAfterChange function is lacking the input it needs from slick. This code should fix it:

 $(document).ready(function(){
      var item_length = $('.slider > div').length - 1;
      $('.slider').slick({
        appendArrows : '.arrow-holder',
        adaptiveHeight : true,
        infinite : false,
        onAfterChange: function(slide, index){
            if( item_length == index ){
                alert("Slide 2");
            };
        }
      }); 
    });

请注意,索引[0]是第一张幻灯片

Note that index[0] is the first slide

这篇关于上一张幻灯片放映警报中的slick.js的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆