在鼠标悬停时停止动画

时间:2011-04-28 08:36:29

标签: javascript jquery

我的鼠标悬停功能可以设置对象的宽度,但是当它到达目的地时,它会来回移动2或3个像素。有没有解决这个问题的方法。

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

3 个答案:

答案 0 :(得分:1)

尝试.stop()

答案 1 :(得分:1)

如果您希望在mouseover上将宽度设置为200像素,然后在mouseout上将其设置为动画(例如:100 px),这可能有所帮助:

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

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

答案 2 :(得分:0)

经常一次stop()单独不会做的伎俩,你需要传递“true”,参数也要清除文档动画队列:

.stop('true', 'true);

此处提供完整文档:

http://forum.jquery.com/topic/stop-true-true-animation-chains-and-callbacks

相关问题