Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check mouse holded some sec on a element

How we can check mouse holed some seconds on an element.

Means that the function should execute only if the user holds the mouse more than minimum seconds(eg:3 sec) on an element.

Many of the answers found in the stack, but that solutions are delaying the execution, but I want to check mouse holed or not, If yes, execute the function else don't make any action.

Already asked same question before, but not yet get the answer exactly what I looking

Is it possible?

like image 364
Jaison James Avatar asked Dec 08 '22 07:12

Jaison James


1 Answers

I think you are looking for this, here if a div gets hover and hold mouse for at least 3 seconds then do your stuff like below

var myTimeout;

$('div').mouseenter(function() {
    myTimeout = setTimeout(function() {
        alert("do your stuff now");
    }, 3000);
}).mouseleave(function() {
    clearTimeout(myTimeout);
});
like image 137
Bhushan Kawadkar Avatar answered Dec 11 '22 10:12

Bhushan Kawadkar