2012-03-17 48 views
1

我有兩個圖像堆疊在一起,試圖用它來導航。在懸停時,我使用jQuery將淡出到0並返回到1時光標離開。這是工作,但這是我的問題。如果您將鼠標光標在列表項上來回多次運行,則會緩衝效果。我如何阻止它從緩衝區?謝謝!如何停止緩衝懸停效果的jQuery?

腳本

$(document).ready(function() { 
$("li").hover(function(){ 
$(this).fadeTo(250, 0); 
},function(){ 
$(this).fadeTo(350, 1); 
}); 
}); 

HTML

<div id="link1img"></div> 

    <ul> 
    <li id="link1"><a href="index.html">Home</a></li> 
    </ul> 

CSS

#link1 { 
background-image: url(../images/home_normal.png); 
background-repeat: no-repeat; 
text-indent: -9999px; 
position: absolute; 
height: 17px; 
width: 67px; 
left: 0px; 
top: 10px; 
} 
#link1img { 
background-image: url(../images/home_mo.png); 
background-repeat: no-repeat; 
position: absolute; 
height: 17px; 
width: 67px; 
left: 0px; 
top: 11px; 
} 
+1

jQuery的不緩衝。你所指的是動畫隊列。除清除隊列的.stop()方法外(如下面的答案中所述)。還有.dequeue()將不會清除隊列,但首先將該動畫放在一行中。 – Fresheyeball 2012-03-17 18:03:39

回答

3

繼續之前停止使用.stop()舊的效果:

$(document).ready(function() { 
    $("li").hover(function() { 
     $(this).stop().fadeTo(250, 0); 
    }, function() { 
     $(this).stop().fadeTo(350, 1); 
    }); 
}); 
1

使用.stop(true)取消任何動畫,目前在該對象上的進展,並從動畫隊列中刪除他們,讓你的下一個動畫可以立即開始,而不必等到當前的一個f食物:

$(document).ready(function() { 
    $("li").hover(function(){ 
     $(this).stop(true).fadeTo(250, 0); 
    },function(){ 
     $(this).stop(true).fadeTo(350, 1); 
    }); 
}); 

查看jQuery reference on .stop()瞭解更多信息。