2011-04-28 204 views
0

我的鼠標懸停功能可以動態顯示對象的寬度,但當它到達目的地時,它會前後移動2或3個像素。有沒有解決這個問題的方法。在鼠標懸停時停止動畫

$(this).mousover(function() { 
    $('myselector').animate({'width': 200}); 
    // this is all have for my animation but it moves alot 
}); 
+0

可否請你創建一個測試用例這個上[的jsfiddle(http://www.jsfiddle.net/)? – mekwall 2011-04-28 08:42:34

+0

我創建了自己的[測試](http://jsfiddle.net/mekwall/3rZAP/),我無法重現您所描述的內容。 – mekwall 2011-04-28 08:45:30

回答

1

如果要動畫寬度200像素的mouseover,然後將其動畫回(例如:100像素)的mouseout這可以幫助:

$(this).mouseover(function() { 
     $('myselector').stop().animate({'width': 200}); 
     }); 

$(this).mouseout(function() { 
      $('myselector').stop().animate({'width': 100}); 
      }); 
1

嘗試.stop()

+0

我在哪裏停止 – ONYX 2011-04-28 08:53:32

+0

這不是真的與他的問題有關。是的,這會停止動畫,但它不能修復littleMan的「2或3個像素」:) – mekwall 2011-04-28 08:55:35