I have a vertically scrollable div inside the page that also scrolls vertically.
When the child div scrolls with the mouse wheel and reaches the top or bottom of the scrollbar, the page (body) starts to scroll. While the mouse is above the child div, I would like the page (body) to scroll to be locked.
This SO post (scroll down to the selected answer) shows the problem well.
This SO question is essentially the same as mine, but the selected answer causes my page content to shift noticeably horizontally when the scroll bar disappears and reappears.
I thought there might be a solution that uses event.stopPropagation () but cannot make anything work. In ActionScript, this solution will be resolved by placing the mousewheel handler on the child div that raises the stopPropagation () event in the event before it reaches the body element. Since JS and AS are ECMAScript languages, I thought the concept could be translated, but it doesn't seem to work.
Is there a solution that prevents the movement of the contents of my page? Most likely using stopPropagation instead of fixing CSS? JQuery answers are welcome, as is pure JS.
javascript html scroll stoppropagation
ericsoco Feb 13 2018-12-12T00: 00Z
source share