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.