Instead of scrolling to the top of the page to ensure the modal is visible, add margin-top to the modal so that it is pushed down to be inside the viewport when opening. This means that you don't lose your scroll position on closing the modal, however opening position is no longer consistent.