Created
November 17, 2011 17:53
-
-
Save tomlane/1373898 to your computer and use it in GitHub Desktop.
Page Visibility API Example
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
<!-- video pauses when tab is not in view. Uses Page Visibility API. --> | |
<html> | |
<head> | |
<title>Page Visibility API</title> | |
</head> | |
<body> | |
<p>Credit for video: http://ptaff.ca/orage_montreal/?lang=en_CA </p> | |
<video> | |
<source src="1696_lightnings.ogg" type="video/ogg"> | |
</video> | |
<script> | |
var v = document.getElementsByTagName("video")[0]; | |
v.play(); | |
function handleVisibilityChange() { | |
if (document.webkitHidden = true) { | |
v.pause(); | |
} else { | |
v.play(); | |
} | |
} | |
document.addEventListener("webkitvisibilitychange", handleVisibilityChange, false); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment