Created
December 12, 2023 18:53
-
-
Save doceazedo/ad4287c895cba86a33ad326665bfa304 to your computer and use it in GitHub Desktop.
Video embed fullscreen scroll position issue
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
// 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