小编use*_*202的帖子

如何从一个函数调用clearInterval()方法来停止另一个函数中的setInterval()方法

所以我基本上使用下面的基本交叉渐变创建幻灯片是我正在使用的脚本

脚本:

  $(document).ready(function(){
        var slide = function(){
                                var active = $('.active');
                                var next = (active.next().length > 0) ? active.next() : $('#slide:first');
                                next.css('z-index',2);
                                active.fadeOut(1000,function(){// fade out the active image
                                                                active.css('z-index',1).show().removeClass('active');
                                                                next.css('z-index',3).addClass('active');
                                });
                              }
        setInterval(slide,2000)
  });
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,上面的脚本每两秒交叉淡出一个图像列表.现在我想做的是clearInterval(Interval id)当用户点击previous image按钮或按钮时停止幻灯片放映(即使用),next image但它似乎工作.我已经尝试过w3schools.com等的示例但无济于事


更新

完整的脚本,如果有任何疑问

  $(document).ready(function(){
        var slide = function(){
                                var active = $('.active');
                                var next = (active.next().length > 0) ? active.next() : $('#slide:first');
                                next.css('z-index',2);
                                active.fadeOut(1000,function(){// fade out the active image
                                                                active.css('z-index',1).show().removeClass('active');
                                                                next.css('z-index',3).addClass('active');
                                });
                              }
        setInterval(slide,2000)
  });

  //------------on …
Run Code Online (Sandbox Code Playgroud)

html javascript jquery slideshow intervals

0
推荐指数
1
解决办法
1100
查看次数

标签 统计

html ×1

intervals ×1

javascript ×1

jquery ×1

slideshow ×1