Created
August 9, 2020 09:47
-
-
Save DmitryMarkov/8592b2e410d985aab1143146f2783f78 to your computer and use it in GitHub Desktop.
Save and restore scroll position
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let sidebar = document.querySelector(".sidebar"); | |
let top = localStorage.getItem("sidebar-scroll"); | |
if (top !== null) { | |
sidebar.scrollTop = parseInt(top, 10); | |
} | |
window.addEventListener("beforeunload", () => { | |
localStorage.setItem("sidebar-scroll", sidebar.scrollTop); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment