javascript - Div1 covers Div2: how to check if the mouse is over the covered Div2? -
i'm bit lost. try check if mouse on div covered div. search vanilla js solution if possible.
i tried use elementfrompoint method, seems give me top div. tried mess around "onmouseover" event, didn't found solution either. maybe overlooked something.
any ideas how solve this? want method check if mouse on smaller div2 or not. made jsfiddle show situation. made covering div translucent easier understanding setup.
<div id="div1"></div> <div id="div2"></div> #div1 { width:300px; height:300px; background:red; position:absolute; top:0px; z-index:1; opacity: 0.5; } #div2 { width:200px; height:200px; background:blue; position:absolute; top:0px; }
if want check if mouse on <div> covered <div>, can achieve declaring code: pointer-events: none; css of covering <div>.
for example:
<div id="under"></div> <div id="over"></div> add css file:
#over{ pointer-events: none; } in case, pointer events div having id=over ignored. can add code test if working.
add javascript code:
$('#under').mouseover(function() { alert("mouse on div having id='under'"); }); give try! luck!
Comments
Post a Comment