Skip to content

Instantly share code, notes, and snippets.

@doceazedo
Created December 12, 2023 18:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save doceazedo/ad4287c895cba86a33ad326665bfa304 to your computer and use it in GitHub Desktop.
Save doceazedo/ad4287c895cba86a33ad326665bfa304 to your computer and use it in GitHub Desktop.
Video embed fullscreen scroll position issue
// Sources:
// https://stackoverflow.com/questions/64304444/is-there-any-way-to-detect-fullscreen-events-in-youtube-iframe-api
// https://stackoverflow.com/questions/45597346/how-do-i-prevent-custom-full-screen-from-resetting-the-scroll-position
let top2 = 0;
const handleFullscreen = () => {
if (document.fullscreenElement) {
top2 = document.querySelector('html').scrollTop;
console.log(`Setting to ${top2}`);
} else {
document.querySelector('html').scrollTop = top2;
console.log(`Moving to ${top2}`);
}
};
document.addEventListener('fullscreenchange', handleFullscreen);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment