gpt4 book ai didi

javascript - 如何防止鼠标进入/离开发生太多次

转载 作者:太空狗 更新时间:2023-10-29 15:52:00 24 4
gpt4 key购买 nike

我有一段代码基本上是这样说的:如果你滚过这个,那么另一个东西就会出现,如果你滚出去,它就会消失。

问题是,如果我拿鼠标滚动/滚出太多次,元素就会出现/消失太多次(因为我错误地为它创建了很多事件)

我的代码是这样的:

$('div.accordionContent').mouseenter(function()
{
$(this).find(".something").animate({left: 0}, 300)}).mouseleave(function() {
$(this).find(".something").animate({
left: -200}, 500);;
});

如何告诉它避免多次悬停?

如果有帮助,我会使用 jQuery 1.4.3..

最佳答案

与其避免多次触发,不如尝试在开始另一个动画之前停止动画。

$('div.accordionContent').mouseenter(function() {
$(this).find(".something").stop().animate(...)
});

关于javascript - 如何防止鼠标进入/离开发生太多次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8471897/

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