Skip to content

Instantly share code, notes, and snippets.

@hassanuos
Created March 16, 2024 05:27
Show Gist options
  • Save hassanuos/6cd318d53bd7cf7e4fc4d8da7af02fd2 to your computer and use it in GitHub Desktop.
Save hassanuos/6cd318d53bd7cf7e4fc4d8da7af02fd2 to your computer and use it in GitHub Desktop.
Easily Pause/Play video based on page visibility state
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