I save current scroll position using the following way:
$(window).on('unload', function() {
if ($(window).scrollTop() != 0) {
localStorage.setItem('lastScrollPosition', $(window).scrollTop());
$(window).scrollTop(0);
}
});
After page reloading I load images and I need to scroll at lastScrollPosition
only when all images are loaded. So I call $(window).scrollTop(lastScrollPosition)
after all images are loaded, browser scrolls at lastScrollPosition
, but after that browser also scrolls at top of page (like $(window).scrollTop(0);
), therefore, I get these action: $(window).scrollTop(lastScrollPosition) -> $(window).scrollTop(0)
Could you please advise how to fix my issue?
I found out the reason of the issue. This way works correctly, but a instagram library scrolls to top after my scroll. So this library has strange behavior.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.