Skip to content

Instantly share code, notes, and snippets.

@tomlane
Created November 17, 2011 17:53
Show Gist options
  • Save tomlane/1373898 to your computer and use it in GitHub Desktop.
Save tomlane/1373898 to your computer and use it in GitHub Desktop.
Page Visibility API Example
<!-- 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