gpt4 book ai didi

javascript - Mouseenter 和 mouseleave 闪烁

转载 作者:行者123 更新时间:2023-11-30 17:43:40 25 4
gpt4 key购买 nike

当我用鼠标点击时,盒子变得可见,但即使我的鼠标停留在盒子上,它也会不断淡入淡出,我做错了什么?

jQuery

    geoThumb = $(".geoThumb");
geoThumb.each(function(){
$(this).mouseenter(function() {
$(".infoBox").fadeIn(500);
}).mouseleave(function(){
$(".infoBox").fadeOut(500);
});
});

最佳答案

添加.stop.fadeIn.fadeOut 之前。

$(".geoThumb").mouseenter(function() {
$(".infoBox").stop().fadeIn(500);
}).mouseleave(function(){
$(".infoBox").stop().fadeOut(500);
});

演示:http://jsfiddle.net/DerekL/R4F9T/

它闪烁是因为当它前面的动画没有完成时,动画正在排队。为防止这种行为,.stop是专门设计的,您可以使用它来清除所有排队的动画。

Quote from jQuery Docs

The usefulness of the .stop() method is evident when we need to animate an element on mouseenter and mouseleave.

关于javascript - Mouseenter 和 mouseleave 闪烁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20556252/

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