Created
March 16, 2024 05:27
-
-
Save hassanuos/6cd318d53bd7cf7e4fc4d8da7af02fd2 to your computer and use it in GitHub Desktop.
Easily Pause/Play video based on page visibility state
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
const video = document.querySelector('video'); | |
document.addEventListner('visibilitychange', () => { | |
if(document.hidden){ | |
video.pause(); | |
}else{ | |
video.play(); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment