Last active
August 29, 2015 14:06
-
-
Save gordonnl/fc8892cbd7231344ea5e to your computer and use it in GitHub Desktop.
Pause Inactive Tab Using visibilitychange
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
var forced = false; | |
var pauseWhileInactive = function() { | |
switch (document.visibilityState) { | |
case 'hidden' : | |
if (!sfx.volume.value) return; | |
forced = sfx.volume.value; | |
sfx.volume.value = 0; | |
break; | |
case 'visible' : | |
if (!forced) return; | |
sfx.volume.value = forced; | |
forced = false; | |
break; | |
} | |
}; | |
document.addEventListener('visibilitychange', pauseWhileInactive); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment