Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overlay div over leaflet and stop mouse action propagation

How would I stop the propagation of clicking and scrolling on a div, overlaying a leaflet map? That seems to be very tricky... Something like

customPreventDefault(e) {
    e = e || window.event;
    if (e.preventDefault)
        e.preventDefault();
    e.returnValue = false;
}

document.getElementById('no-scrolling-clicking').onmousewheel =
    function (e) {
        document.getElementById('prevent-scrolling').scrollTop -= e.wheelDeltaY;
        customPreventDefault(e);
    }
}

doesn't do anyhting. It needs to work in IE as well...

http://jsfiddle.net/LnzN2/4888/

like image 661
Stophface Avatar asked Sep 13 '18 08:09

Stophface


1 Answers

Move your parent-div outside of the map div.

Change your HTML to:

<div 
  id="map">

</div>
<div 
  id='parent-div'
  class='some-div'>
   I am the parent! Like the leaflet map, I don't want the mouse events clicking/scrolling bubbling onto me neither.
    <div 
      class='some-div'
      id='no-scrolling-clicking'>
      Stop Scrolling and clicking Event in me! Stop Scrolling and clicking Event in me! Stop Scrolling and clicking Event in me! Stop Scrolling and clicking Event in me! Stop Scrolling and clicking Event in me! Stop Scrolling and clicking Event in me! Stop Scrolling and clicking Event in me! Stop Scrolling and clicking Event in me! Stop Scrolling and clicking Event in me! Stop Scrolling and clicking Event in me!
    </div>
  </div>
like image 65
Worm Avatar answered Nov 15 '22 09:11

Worm