Created
June 16, 2021 07:45
-
-
Save dsgeyser/7934df1df8fe35dc894571ad4319eaff to your computer and use it in GitHub Desktop.
xxqMKNB
This file contains hidden or 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
<main> | |
<h3>Page Visibility API Demo</h3> | |
<video id="my-video" width="400" controls=""> | |
<source id='mp4' src="https://alligator.io/images/js/page-visibility-api/bbb-360p.mp4" type='video/mp4' /> | |
<p>Sorry, there's a problem playing this video. Please try using a different browser</p> | |
</video> | |
<p>Video thanks to the Blender Foundation | <a href="https://www.blender.org/">www.blender.org</a></p> | |
<a href="tel:8882192787">Call us at 888-219-2787</a> | |
</main> |
This file contains hidden or 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
window.onload = function() { | |
document.addEventListener("visibilitychange", () => { | |
const video = document.getElementById("my-video"); | |
console.log(document.hidden); | |
return document.hidden ? video.pause() : video.play(); | |
}); | |
}; |
This file contains hidden or 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
body { | |
background-color: gray; | |
font-family: "Helvetica", sans-serif; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment