/ Published in: jQuery
I created this snippet for a personal project, where i needed to open a tooltip only when the user was over or moving the mouse after X seconds in a specific selector.
In the code you will find "your code goes here" where you can play around like showing or hiding divs, or whatever are your needs.
In the code you will find "your code goes here" where you can play around like showing or hiding divs, or whatever are your needs.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$(this).mouseover(function(){ $seconds = 0; $timer = 0; count(); function count(){ $seconds = setTimeout(function() { count(); }, 1000); $timer = $timer + 1; if($timer == 2){ // your code goes here... clearTimeout($seconds); } } }).mousemove(function(kmouse){ if($timer == 2){ // your code goes here... clearTimeout($seconds); } }).mouseout(function(){ clearTimeout($seconds); // your code goes here... });