JQuery Mouse Time Over Element (Hover)

I have a hover event associated with multiple links, and when you go through it, a window appears.

Is there a way that I can only make a hang event a trigger if the mouse has been following the link for more than 500 ms? So, as soon as the mouse follows the link, a window will appear, but I want it to appear only if the mouse has been above the field for 500 ms or longer.

+3
source share
2 answers
var myTimeout;
$('#mylink').mouseenter(function() {
    myTimeout = setTimeout(function() {
        //do stuff
    }, 500);
}).mouseleave(function() {
    clearTimeout(myTimeout);
});
+18
source

Here's a great jQuery plugin to help you decide if mouse movement is suitable for triggering an action. It is called hoverIntent

+2
source

Source: https://habr.com/ru/post/1782980/


All Articles