jQuery 时间鼠标悬停在元素上(悬停)

发布于 2024-10-09 21:46:27 字数 140 浏览 0 评论 0原文

我有一个悬停事件附加到几个链接,当你点击它时会出现一个框。

有没有一种方法可以让悬停事件仅在鼠标悬停在链接上超过 500 毫秒时触发?因此,目前,只要鼠标移到链接上,就会出现该框,但我希望只有当鼠标悬停在该框上 500 毫秒或更长时间时,它才会出现。

i have a hover event attached to a few links and when you go over it a box appears.

Is there a way that i can make the hover event only trigger if the mouse has been over the link for more then 500 ms? So currently as soon as the mouse goes over the link the box appears but i want it to only appear if the mouse has been over the box for 500 ms or longer.

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

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

发布评论

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

评论(2

橙味迷妹 2024-10-16 21:46:27
var myTimeout;
$('#mylink').mouseenter(function() {
    myTimeout = setTimeout(function() {
        //do stuff
    }, 500);
}).mouseleave(function() {
    clearTimeout(myTimeout);
});
var myTimeout;
$('#mylink').mouseenter(function() {
    myTimeout = setTimeout(function() {
        //do stuff
    }, 500);
}).mouseleave(function() {
    clearTimeout(myTimeout);
});
最笨的告白 2024-10-16 21:46:27

这是一个很棒的 jQuery 插件,可以帮助您确定鼠标移动是否适合启动操作。
它称为 hoverIntent

Here's a great jQuery plugin that helps you decide if the mouse movement is appropriate for initiating an action.
It is called hoverIntent

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