jQuery Time mouse is over element (Hover)

帅比萌擦擦* 提交于 2020-01-01 06:56:15

问题


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.


回答1:


var myTimeout;
$('#mylink').mouseenter(function() {
    myTimeout = setTimeout(function() {
        //do stuff
    }, 500);
}).mouseleave(function() {
    clearTimeout(myTimeout);
});



回答2:


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



来源:https://stackoverflow.com/questions/4573293/jquery-time-mouse-is-over-element-hover

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!