0

I have a page which is long enough to scroll on. On this page I have a button and when I click on that button it displays a div with position fixed and is also long enough to scroll. When I press esc the div closes.

The problem is that when I press esc (to close the div) while I am scrolling in that div, the scrolling continues on the page. I don't want to disable scrolling, I just want to stop that current scrolling. How do I do that?

MrMaavin
  • 1,611
  • 2
  • 19
  • 30
Luc Drenth
  • 3
  • 1
  • 4
  • did you try a `event.stopPropagation()` on the div you are closing, so the scroll event does not propagate to a parent node? (for a [scroll event](https://developer.mozilla.org/en-US/docs/Web/Events/scroll)) – Cinn Jan 23 '19 at 13:00
  • I set `event.stopPrpagation();` before hiding it and it did not work – Luc Drenth Jan 23 '19 at 13:07
  • Possible duplicate of [How to disable scrolling temporarily?](https://stackoverflow.com/questions/4770025/how-to-disable-scrolling-temporarily) – Siavas Jan 23 '19 at 13:07
  • This is complicated because i guess it comes from the _smooth_ effect, so a dirty solution could be to keep in memory the last time your div has been scrolled, and then add an `eventListener` on the normal page which does a `event.preventDefault()` if your div has just been scrolled. This is dirty but it worked, i am interested to see if a better way exists... – Cinn Jan 23 '19 at 13:14

0 Answers0