0

I have a scrollable feed on my site for user posted content. There is a button that triggers a popup/overlay that should pause the scrolling. I found a way to pause on a pc browser, but I am unable to pause the scrolling on my iPhone causing a weird visual glitch that shows the content behind the popup/overlay still scrolling as if it were the content ontop.

I have tried changing position to fixed, but this will not save the location of the user before they clicked the popup/overlay button. Instead it will return the user to the top of the page. I want to freeze the user however far down the screen they were so when they close the popup they will be able to scroll again.

<script>
            function NewPostPopup() {
                const noscroll = document.getElementById("newpostpopup").classList.toggle("active");
                if (noscroll) {
                    document.body.style.overflow = "hidden";
                } 
                else {
                    document.body.style.overflow = "auto";
                }
            }
        </script>
adamcapjones
  • 185
  • 1
  • 17
  • https://stackoverflow.com/questions/3047337/does-overflowhidden-applied-to-body-work-on-iphone-safari this is not answer for you? – David F Dec 26 '22 at 20:02

1 Answers1

0

add this style

body {
  position: fixed;
}

and this logic:

window.addEventListener("scroll", (e) => {
  e.preventDefault();
  window.scrollTo(0, 0);
});
Mohammad Nazari
  • 137
  • 1
  • 12