2011-04-28 182 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