-
-
Save anthony-wang/1c04e52ed73c2fd41522f31a9af4f8f2 to your computer and use it in GitHub Desktop.
Synchronized scrolling (and zooming) across browser tabs
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
javascript:(function()%7Bwindow.addEventListener(%20'scroll'%2C%20(e)%20%3D%3E%20%7B%20localStorage.setItem('scrollY'%2C%20scrollY)%3B%20localStorage.setItem('zoom'%2C%20document.body.style.zoom)%3B%20%7D%20)%3Bwindow.addEventListener(%20'storage'%2C%20(e)%20%3D%3E%20%7B%20if%20(e.key%20%3D%3D%3D%20%22scrollY%22)%20%7B%20y%3DparseInt(e.newValue)%3B%20window.scrollTo(0%2C%20y)%3B%20%7D%3B%20if%20(e.key%20%3D%3D%3D%20%22zoom%22)%20%7B%20document.body.style.zoom%3De.newValue%3B%20%7D%3B%20%7D%20)%7D)() |
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
window.addEventListener( 'scroll', (e) => { localStorage.setItem('scrollY', scrollY); localStorage.setItem('zoom', document.body.style.zoom); } ); | |
window.addEventListener( 'storage', (e) => { if (e.key === "scrollY") { y=parseInt(e.newValue); window.scrollTo(0, y); }; if (e.key === "zoom") { document.body.style.zoom=e.newValue; }; } ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment