在Hover jQuery Cycle上启动脚本



我在我的实践网页设计中做过jQuery循环。我的问题是,我希望脚本开始鼠标悬停,但发生了什么是当我刷新页面,它已经开始。鼠标移到第一个位置时,它停止了。然后第二个鼠标移过来,它开始做幻灯片,当鼠标移出时停止。下面是代码:

jQuery(function($){
    // Cycle plugin
    $('.slides').cycle();
    // Pause & play on hover
    $('.slideshow-block').hover(function(){
        $(this).find('.slides').addClass('active').cycle('resume');
    }, function(){
        $(this).find('.slides').removeClass('active').cycle('pause');
    });
});

我试着把"暂停"或"暂停"在$('.slides').cycle();,但它实际上破坏了插件,没有更多的效果。谢谢你的帮助!:)

您可以使用.mouseover, .mouseout, .mouseenter.mouseleave来更好地控制您的鼠标动作。

的例子:

$(".slideshow-block").mouseover(function() {
  $(this).find(".slides").addClass('active').cycle('resume');
}).mouseout(function(){
  $(this).find(".slides").removeClass('active').cycle('pause');
});

我已经找到了答案,我只是这样做:

$('.slides').cycle().cycle('pause');

最新更新