2011-05-08 94 views
2
$("a").hover(function(){ 
    $(this).animate({left: '-500px'}, 'slow'); 
); 

我使用此代碼來爲鏈接的位置設置動畫。我用slow動畫速度將它移動到左邊角落。使用jQuery更改動畫速度

我如何改變這個動畫的速度fast,點擊鏈接時?

我們應該:

  • slow動畫當鏈接徘徊。
  • fast被點擊時它。

問題是,當我們嘗試點擊鏈接時,鏈接可能已經生成動畫。你怎麼看?

謝謝。

+0

您可以指定的時間間隔作爲第二個參數...這會照顧 – kobe 2011-05-08 17:47:53

回答

5
$("a").hover(function(){ 
    $(this).animate({left: '-500px'}, 'slow'); 
).click(function() { 
    $(this).dequeue().animate({left: '-500px'}, 'fast'); 
}); 
0

你可以嘗試:

$("a").click(function(){ 
    $(this).stop(true).animate({left: '-500px'}, 'fast'); 
); 

(未測試)

0

這可能會實現,利用stop()已經停止任何動畫運行。

$("a").click(function(){ 
    $(this).stop() 
    $(this).animate({left: '-500px'}, 'fast'); 
);