I was pretty impressed with this feature like when scrolling in the feeds page and then clicking in some post then redirecting it to that post and then if we click the browser's back button it automatically brings the browser's viewport to the continuation from where we left in the feeds page. like if there are 20 posts then i clicked on 8th post and then after returning to the feeds page again the page offset is in the position of the 8th post only...So if we want to go up then scroll up else normal scrolling down .
It's really a very user friendly interaction.
Thanks
One option imho would be to:
// on browser back, load old page and set scroll position
window.addEventListener('popstate', eve => {
if (eve.state.scrollPos) {
// load old page
// change address bar
document.documentElement.scrollTop = document.body.scrollTop = eve.state.scrollPos;
}
});
// on anchor click, store scroll position and load new page
for (let a of document.querySelectorAll('a')) {
a.addEventListener('click', eve => {
history.pushState(
{
scrollPos: window.pageYOffset || document.documentElement.scrollTop,
},
null,
window.location.toString()
);
// load new page
// change address bar
}
}
dan
salesforce
oh dang