Keep checking state instead of single check in jquery / js

What I would like to achieve is when the mouse does not hang in menu 3, the system will continue to check if the aboutMenu symbol is visible, if so, the warning “h” and the warning “nh” otherwises. The problem is that only once when the mouse leaves menu3, how to solve this problem? thanks.

$('#menu3').live('mouseout',function() { $("#aboutMenu").hover(function() { $(this).data("hovered", true); }, function() { $(this).data("hovered", false); }); if ( $("#aboutMenu").data("hovered") ) { alert ('h'); } else { alert ('nh'); } }); 

Updated:

Or another way to do this - the system constantly checks whether menu3 or aboutMenu is popping up, if not, a pop-up hanging message. However, this will only be done once, when the page is initialized, how do I get it to continue checking? thanks

 $(document).ready(function() { $("#aboutMenu,#menu3").hover(function() { $(this).data("hovered", true); }, function() { $(this).data("hovered", false); }); if ( $("#aboutMenu,#menu3").data("hovered") ) alert ('hovered'); }); 
+6
source share
2 answers
 function checkHover() { if ($("#aboutMenu,#menu3").hasClass("hovered")) { alert ('hovered'); //other stuff if hovered } else { //other stuff if not hovered } } $(document).ready(function() { $("#aboutMenu,#menu3").hover(function() { $(this).addClass("hovered"); }, function() { $(this).removeClass("hovered"); }); setInterval(checkHover, 1000); }); 
+4
source

Would it be a problem to periodically check the state of a hoverstate?

 function chkhover(){ if ($('#aboutMenu').is(':hover')){ alert('#aboutMenu hoverstate is: hovered'); } setTimeout(chkhover, 500); } $(document).ready(chkhover); 

See jsfiddle . By the way, this also demonstrates the css solution.

+1
source

All Articles