限制和动画功能

Limit and Animate Function

本文关键字:功能 动画      更新时间:2023-09-26

我相信这个问题已经有很多答案了,但问题是我不知道该搜索什么。我基本上是想在用户将鼠标放在另一个对象上时使用animate函数来向上移动元素,并在用户移出鼠标时将其向后移动。我让它工作得很好,但我不知道如何限制它,这样他们就不能很快地将鼠标移入和移出元素多次,然后停止让对象在进入元素时继续动画。

$('.cover_1').mouseover(function() {
    $('.pop_1').animate({bottom: "0px"}, 100);
}).mouseout(function(){
    $('.pop_1').animate({bottom: "-300px"}, 100);
});  

这就是我现在拥有的代码。

尝试使用停止方法,如:

$('.cover_1').mouseover(function() {
    $('.pop_1').stop(true,true).animate({bottom: "0px"}, 100);
}).mouseout(function(){
    $('.pop_1').stop(true, true).animate({bottom: "-300px"}, 100);
});