gpt4 book ai didi

jquery - 取消鼠标悬停时的 mouseleave 事件

转载 作者:行者123 更新时间:2023-12-01 03:42:37 25 4
gpt4 key购买 nike

我正在尝试复制此页面上的效果:http://blacknegative.com/#!/bullittagency/ (您可能需要向右滑动,单击“菜单”并选择第 04 部分才能看到它)

这是我到目前为止所拥有的:http://codepen.io/semajtwin/pen/IcBxu

问题是,反复将鼠标从一个框移动到另一个框,mouseleave 事件仍然会被触发。如果鼠标回到 div 上,我正在尝试找到一种方法来取消 div 上的 mouseleave 事件。也许有更好的方法来做到这一点。

jQuery:

$(document).ready(function() {

$('.item').mouseenter(function() {
$(this).css({
'opacity': 0
});
}).mouseleave(function() {
$(this).delay(300).animate({
'opacity': 1
}, 500);
});
});

提前致谢。

最佳答案

您可以使用stop()函数来停止在 mouseleave 事件中创建的动画:

$(document).ready(function() {

$('.item').mouseenter(function() {
$(this).stop().css({
'opacity': 0
});
}).mouseleave(function() {
$(this).delay(300).animate({
'opacity': 1
}, 500);
});
});

<强> Working Demo

关于jquery - 取消鼠标悬停时的 mouseleave 事件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17785959/

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