gpt4 book ai didi

JQuery + MouseOver 重置淡出

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

我有以下代码,显示一个下拉框,该下拉框淡出然后被删除:

$('.containerDIV').show().fadeOut(10000, function() {$(this).remove();});

上面的代码运行良好,但我想更新它,这样如果用户将鼠标放在 $('.containerDIV') 上,淡出就会停止,当鼠标移出时,淡出会再次开始。

希望有人能插入我朝正确的方向前进。

最佳答案

一种解决方案是使用.stop(true, false) ,这将停止任何当前动画并清除动画队列。然后你可以使用fadeIn(0)立即再次显示 div。

// Cache DIVs
var $containerDIVs = $('.containerDIV');

// Start Initial Fade
FadeAndRemove($containerDIVs);

// On mouseover, stop fade and show again
$containerDIVs.on("mouseover", function(e) {
$(this).stop(true /*, false implied */ ).fadeIn(0);
});

// On mouse leave, start fade again
$containerDIVs.on("mouseleave", function(e) {
FadeAndRemove(this);
});

// Fading function
function FadeAndRemove(els) {
$(els).fadeOut(10000, function() {
$(this).remove();
});
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<div class="containerDIV">
testing 123
<select>
<option>1</option>
</select>
</div>

参见Fiddle

关于JQuery + MouseOver 重置淡出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31632281/

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