gpt4 book ai didi

jQuery 在开始新动画之前退出动画

转载 作者:行者123 更新时间:2023-12-01 08:18:31 26 4
gpt4 key购买 nike

我有:

$('.p_m').mouseenter(function () {

$(this).animate({
marginTop: '10px',
marginLeft: '10px',
height: '150px',
width: '150px'
}, 10000);

}).mouseleave(function () {

$(this).animate({
marginTop: '35px',
marginLeft: '35px',
height: '100px',
width: '100px'
}, 10000);
});

当我离开类 '.p_m' 的速度快于 10000 毫秒时,即使我离开 div 类,mouseenter 动画也会继续运行。

如何跳过动画(鼠标输入)或更好地使其快速以适合 10000 毫秒。

最佳答案

使用.stop()停止当前动画。

$('.p_m').mouseenter(function () {

$(this).stop().animate({
marginTop: '10px',
marginLeft: '10px',
height: '150px',
width: '150px'
}, 10000);

}).mouseleave(function () {

$(this).stop().animate({
marginTop: '35px',
marginLeft: '35px',
height: '100px',
width: '100px'
}, 10000);
});

如果您希望动画在开始新动画之前跳到末尾,请传递 true 作为第二个参数。 .stop(true,true)

关于jQuery 在开始新动画之前退出动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8862817/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com