css - Checking if mouse is over something in jQuery? -


i have found other people have asked in past told use :hover, doesn't exist anymore. there way boolean out of .hover()?

i'm using .hover() in order make div appear when mouseover button, , disappears when mouseout. however, add check, div won't disappear unless mouse not on button , mouse out of div.

something should work...

var $in_div = 0;  $("div").mouseenter( function(){    $in_div = 1; }).mouseleave( function(){    $in_div = 0; });  $("button").mouseenter( function(){     $("div").show(); }).mouseleave( function(){     if ( $in_div == 1 ) { $("div").hide() } }); 

this method use, delaying hide 500ms, can interrupt if want (in case, if user leaves button enters div).

var $delay = 0; $("button").mouseenter( function(){     cleartimeout( $delay ); // don't hide     $("div").show(); }).mouseleave( function(){     $delay = settimeout( function(){ $("div").hide() }, 500 ); }); $("div").mouseenter( function(){     cleartimeout( $delay ); // don't hide }); 

Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -