2022-12-02 12:03:46 -05:00
|
|
|
let siteNav = document.querySelector('.site-nav');
|
2023-01-26 11:14:26 -05:00
|
|
|
const key = 'scroll';
|
2022-12-02 12:03:46 -05:00
|
|
|
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
2023-01-26 11:14:26 -05:00
|
|
|
const scroll = JSON.parse(sessionStorage.getItem(key));
|
|
|
|
|
|
|
|
const currentDate = new Date();
|
|
|
|
|
|
|
|
if (scroll !== null && currentDate.getTime() < scroll.expiry) {
|
|
|
|
siteNav.scrollTop = parseInt(scroll.value);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
sessionStorage.removeItem(key);
|
2022-12-02 12:03:46 -05:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
window.addEventListener('beforeunload', () => {
|
2023-01-26 11:14:26 -05:00
|
|
|
const currentDate = new Date();
|
|
|
|
|
|
|
|
// add the scroll value that expires after one day
|
|
|
|
const scroll = {
|
|
|
|
value: siteNav.scrollTop,
|
|
|
|
expiry: currentDate.getTime() + 24 * 60 * 60 * 1000,
|
|
|
|
}
|
|
|
|
|
|
|
|
sessionStorage.setItem(key, JSON.stringify(scroll));
|
|
|
|
});
|