-
-
Save stjordanis/86c9bfcd143568b5fe6459dbe583a8db to your computer and use it in GitHub Desktop.
Synchronized scrolling (and zooming) across browser tabs
This file contains hidden or 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 hidden or 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