2015-05-13 40 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); 
    }); 

});