2013-04-25 120 views
0

我在练习网页设计中完成了jQuery循环。我的问题是,我希望脚本从鼠标悬停开始,但是当我刷新页面时,会发生。在我的第一只鼠标上,它停止。然后第二只鼠标结束,它开始进行幻灯片放映,并在鼠标移出时停止播放。下面的代码:在Hover上启动脚本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();但它实际上破坏了插件,并没有更多的影响。谢谢您的帮助! :)

回答

0

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

例子:

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

我发现已经是答案,我只是这样做:

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