2011-11-26 110 views
0

我需要一種方法來停止在mouse enter()上觸發的動畫,如果它是mouse leave()。此時此代碼意味着如果用戶快速滾動然後快速出現,動畫將完成動畫,然後按順序執行mouse leave()函數,而不是在鼠標離開時停止它的軌跡並從那裏動畫。動畫的JQuery停止()方法

我相信這可以用stop()函數完成,但我不知道如何使用它。

$(".featuredslider a").mouseenter(function(){ 
     $(this).stop(); 
     $(this).find('.smallcont').animate({opacity:0},400); 
     $(this).find('.bigcont').animate({opacity:1},400); 
    }); 
    $(".featuredslider a").mouseleave(function(){ 
     $(this).stop(); 
     $(this).find('.smallcont').animate({opacity:1},400); 
     $(this).find('.bigcont').animate({opacity:0},400); 
    }); 

回答

1

文檔是here

但是它是相當簡單的,我相信你想要的東西,如:

$(".featuredslider a").mouseenter(function(){ 
    $(this).find('.smallcont').stop().animate({opacity:0},400); 
    $(this).find('.bigcont').stop().animate({opacity:1},400); 
}); 
$(".featuredslider a").mouseleave(function(){ 
    $(this).find('.smallcont').stop().animate({opacity:1},400); 
    $(this).find('.bigcont').stop().animate({opacity:0},400); 
}); 

這將停止已經開始的每個對象的任何動畫,然後啓動animate()功能後, stop()

+0

奇妙... 7分鐘,直到我可以接受 –

+0

沒有probs ... :-)很高興我有幫助 – ManseUK