Save sidebar scroll position

https://twitter.com/hakimel/status/1262337514741706752
javascript
let sidebar = document.querySelector('.sidebar')
let top = sessionStorage.getItem('sidebar-scroll')
if (top !== null) {
sidebar.scrollTop = parseInt(top, 10)
}
window.addEventListener('beforeunload', () => {
sessionStorage.setItem('sidebar-scroll', sidebar.scrollTop)
})
Edit this page
Want to make your own site like this? Try gatsby-theme-code-notes by Zander Martineau.
Notes on code. My memory bank, by Zander Martineau.