2012-08-30 39 views
1

我有的是工作,但我想看看是否有寫代碼更好的方法,我也越來越對鼠標離開的延遲。實際的動畫正在以所需的速度發生,但在我的鼠標離開之後,它似乎需要大約2-3秒才能完成任何操作。JQuery的動畫使用保證金

CSS被initally設定保證金左:-64px

$('.homeButton').mouseover(function(){ 
    $('.homeButton').animate({marginLeft:'0px'},'slow'); 
}); 

$('.homeButton').mouseleave(function(){ 
    $('.homeButton').animate({marginLeft:'-64px'},200); 
}); 

回答

1

您可以使用stophover方法。

停止對匹配元素當前正在運行的動畫。

$('.homeButton').hover(function(){ 
    $(this).stop(true, true).animate({marginLeft:'0px'},'slow'); 
}, function(){ 
    $(this).stop(true, true).animate({marginLeft:'64px'},'slow'); 
})