Skip to content

Instantly share code, notes, and snippets.

@shawwn
Created April 1, 2021 03:24
Show Gist options
  • Save shawwn/d3705c52dd952255854a4963273f44e6 to your computer and use it in GitHub Desktop.
Save shawwn/d3705c52dd952255854a4963273f44e6 to your computer and use it in GitHub Desktop.
Synchronized scrolling (and zooming) across browser tabs
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)()
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