jQuery 悬停在孩子身上时的怪异

发布于 2025-01-04 07:33:00 字数 185 浏览 4 评论 0原文

http://jsfiddle.net/GNQyt/

将鼠标悬停在绿色框上,然后将鼠标移至子列表。突然开始疯狂地眨眼,无论如何要防止这种情况但保持悬停在孩子上方

*之后编辑

http://jsfiddle.net/GNQyt/

Hover over green box, then move mouse to child list. Suddenly starts blinking like mad, anyway to prevent this but maintain the hover still over child?

*edited afterward

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

初雪 2025-01-11 07:33:00

这是您的工作代码 http://jsfiddle.net/GNQyt/18
我用的是延迟的方法。离开 .icn 后,您有 1000 毫秒到达 ul。如果您在所需的时间内点击 ul,淡出的请求就会被删除。

$('.icn').on({
    mouseenter: function() {

        clearTimeout($(this).data('timeoutId'));

        $(this).children('ul').show('fast');
    },
    mouseleave: function() {

        var self = this;

        var timeoutId = setTimeout(function() {
            $(self).children('ul').hide('fast');
        }, 1000);

        $(self).data('timeoutId', timeoutId); 
    }
});​

Here is your working code http://jsfiddle.net/GNQyt/18
I used the delay method. You have 1000ms once you leave the .icn to reach the ul. If you hit the ul in the desired time, the request for fading it out gets removed.

$('.icn').on({
    mouseenter: function() {

        clearTimeout($(this).data('timeoutId'));

        $(this).children('ul').show('fast');
    },
    mouseleave: function() {

        var self = this;

        var timeoutId = setTimeout(function() {
            $(self).children('ul').hide('fast');
        }, 1000);

        $(self).data('timeoutId', timeoutId); 
    }
});​
表情可笑 2025-01-11 07:33:00

http://jsfiddle.net/GNQyt/5/

使用 mouseenter,而不是悬停在这种情况下

这是“Mouseenter”与“Mouseover”的一个很好的互动比较 http://api.jquery.com/mouseover/

Demo说的很清楚了。

http://jsfiddle.net/GNQyt/5/

Use mouseenter, not hover in that case

Here is a nice little interactive comparison of "Mouseenter" vs. "Mouseover" http://api.jquery.com/mouseover/

The Demo makes it very clear.

江湖彼岸 2025-01-11 07:33:00

闪烁是由于从绿色框移至弹出窗口而导致的。到 之间的距离导致计算机关闭弹出窗口,因为您已远离绿色框,但就在弹出窗口完全关闭之前,鼠标到达弹出窗口,导致其再次打开。理想情况下,两者应该相交,以允许鼠标直接从框移动到弹出窗口。或者,增加关闭弹出窗口之前的延迟。

The flicker is resulting from moving away from the green box and to the pop-up. The distance between the to causes the computer to close the pop-up because you've moved away from the green box, but just before the pop-up is completely closed, the mouse arrives at the pop-up, causing it to open again. Ideally, the two should intersect to allow the mouse to move directly from the box to the pop-up. Or, increase the delay before closing the pop-up.

神妖 2025-01-11 07:33:00

闪烁不是因为悬停子项而是因为在关闭菜单时捕获了菜单。将菜单左上角移动 top: 0px; left: 0px; 解决了这个问题。此外,通过 height: 500px 更改跨度的高度和宽度; width: 500px; 也解决了。为了使高度和宽度有效,请将跨度更改为 div。

Flickering is not because of hovering the child but catching the menu when it is being closed. Moving the menu top left by top: 0px; left: 0px; solves it. Moreover changing height and width of the span by height: 500px; width: 500px; also solves. In order to be height and width to be effective change the span to div.

往事风中埋 2025-01-11 07:33:00

http://jsfiddle.net/GNQyt/17/

这是另一个带有碰撞箱的解决方案。这个几乎被黑客攻击了,但我想你会从中有所了解:)

请记住这

<span>
    <div>
    </div>
</span>

是一种非法操作,因为你不应该将块元素包装到内联元素中。

http://jsfiddle.net/GNQyt/17/

Here's another solution with a hitbox. This one is pretty much hacked, but i think you will get a sense out of it :)

Please keep in mind that

<span>
    <div>
    </div>
</span>

is an illegal operation, since you shouldnt wrap block elements into inline elements.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文