Hi hannahklewin,
Normally this is taken care of by the browser, but in the case of a Wix website the scroll position is reset after a couple of seconds (after loading of the page finished).
I think what you’re trying to achieve might in theory be possible, but very complex and probably slowing things down badly:
- Upon scrolling or leaving the page, trigger a function that retrieves the current scroll position
- You can retrieve the current scroll position using the wix-window getBoundingRect function (see wix-window documentation)
- Assign the output of windowSizeInfo.scroll.y to a variable
- Retrieve the ID of the current page using $w(“PageName”).id
- Store the scrollposition and page ID in your browser’s local or session storage (see wix-storage documentation)
- Upon entering a page, retrieve the stored scroll position of the current page ID
- Restore this scroll position using the scrollTo function (see wix-window documentation)
The problem with this approach is that (as far as I’m aware of) there is no easy way to detect a scrolling-, page enter- and page leave event in Wix Code. There used to be one called $w.ScrollEvent, but it no longer works since mid 2016.
Good luck! Michiel