2015-05-13 157 views
0

那么它绝对看起来,互联网并没有解决这个问题呢。切换图像悬停jquery

我需要旋转/淡入淡出/滑动十个左右的img,在悬停时堆叠在彼此顶部。以这种方式

$(function(){ 
$('.preview img:gt(0)').hide(); 
setInterval(function(){ 
    $('.preview :first-child').fadeOut().next('img').fadeIn().end().appendTo('.preview');}, 
    200); 
}); 

除了我需要踢它,并停止它与悬停,我不能完成。我试图添加活动类等,但与悬停启动时,它只是翻转出来

+0

请创建一个http:// jsfiddle.net演示您的HTML和来自http://lorempixel.com或http://placehold.it的图像。 – isherwood

回答

0

setInterval方法返回的句柄,您可以使用停止区间:

$(function(){ 
    $('.preview img:gt(0)').hide(); 

    var handle; 

    $('.preview').mouseover(function(){ 
    handle= setInterval(function(){ 
     $('.preview :first-child').fadeOut().next('img').fadeIn().end().appendTo('.preview');}, 
    200); 
    }); 

    $('.preview').mouseout(function(){ 
    clearInterval(handle); 
    }); 

});