Search code examples
javascriptiospanel

How to resume normal scrolling after: window.onscroll = function () { window.scrollTo(0, 0);


I have a panel that opens but on IOS the body is scrolling behind the panel.

I am using window.onscroll = function () { window.scrollTo(0, 0); to stop the page scrolling behind the panel when the panel is open.

However, I need to resume normal scrolling afterwards in an event handler. What javascript can I use to resume normal scrolling? as currently when the panel is closed when you try to scroll you get positioned back to (0,0) of the window.

Thank you!


Solution

  • When the panel is opened you set the onscroll function

    window.onscroll = function () { window.scrollTo(0, 0);}
    

    when the panel is closed:

    window.onscroll = null;