The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Page scrolls to top when I close popup

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
  • #256045
    Ollie Williams

    I wanted to disable scrolling on mobile whenever a popup is shown by setting the body to position: fixed. This had the desired effect of stopping scrolling on the body element but I remove position:fixed when the user closes the popup. Going from position: fixed to relative or static moves the screen to the top of the page. This is not what I want – I want the user to be where they were on the page at the point when they opened the popup.


    You’ll need to show some code so that someone here can better troubleshoot the issue.

    At a base level though, I wonder if it might not be due to how you’re allowing users to close the page? For example, if you use something like <a href="#null" id="close-popup"> the #null bit might force the browser to scroll back up to the top as it seeks a matching target.


    Or if you use anchor tag, your href=”#”? This will cause the browser to go to top position. If this is the case, then prevent default in JS.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘CSS’ is closed to new topics and replies.