0

I have a hopefully rather simple Javascript question for you. I have a scrollable, static page which can show/hide a full frame overlay (hiding the whole page) using z-index. When the overlay is shown I create a new event listener to "keydown" in which I for example check for "ArrowDown". When the overlay is hidden, the listener is unsubscribed.

This works beautifully, except that the page below the overlay keeps scrolling up and down as it normally would. I thought I could stop that by using

event.stopPropagation()

which, however, does not help. How can I approach this?

Brian Tompsett - 汤莱恩
  • 5,195
  • 62
  • 50
  • 120
Alex
  • 345
  • 3
  • 10

1 Answers1

1

Event.stopPropagation() Prevents the event from bubbling up the DOM, but does not stop the browsers default behaviour.

event.preventDefault();

this should work as it stops the browsers default behaviour.

Mosè Raguzzini
  • 12,776
  • 26
  • 36
  • 1
    Hm I thought I also tried that already. Let me check again. Edit: Thanks very much, I must have been mistaken - that works beautifully! – Alex Jan 08 '19 at 10:05