我的鼠标悬停功能可以动态显示对象的宽度,但当它到达目的地时,它会前后移动2或3个像素。有没有解决这个问题的方法。在鼠标悬停时停止动画
$(this).mousover(function() {
$('myselector').animate({'width': 200});
// this is all have for my animation but it moves alot
});
我的鼠标悬停功能可以动态显示对象的宽度,但当它到达目的地时,它会前后移动2或3个像素。有没有解决这个问题的方法。在鼠标悬停时停止动画
$(this).mousover(function() {
$('myselector').animate({'width': 200});
// this is all have for my animation but it moves alot
});
如果要动画宽度200像素的mouseover
,然后将其动画回(例如:100像素)的mouseout
这可以帮助:
$(this).mouseover(function() {
$('myselector').stop().animate({'width': 200});
});
$(this).mouseout(function() {
$('myselector').stop().animate({'width': 100});
});
通常情况下,stop()本身不会执行这个技巧,您需要通过“true”参数来清除文档动画队列:
.stop('true', 'true);
完整的文档在这里:
http://forum.jquery.com/topic/stop-true-true-animation-chains-and-callbacks
可否请你创建一个测试用例这个上[的jsfiddle(http://www.jsfiddle.net/)? – mekwall 2011-04-28 08:42:34
我创建了自己的[测试](http://jsfiddle.net/mekwall/3rZAP/),我无法重现您所描述的内容。 – mekwall 2011-04-28 08:45:30