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
Post a Comment