Skip to content

Instantly share code, notes, and snippets.

@sergebat
Created February 21, 2014 14:12
Show Gist options
  • Save sergebat/9134951 to your computer and use it in GitHub Desktop.
Save sergebat/9134951 to your computer and use it in GitHub Desktop.
visibilitychange example
(function() {
var hidden = "hidden";
// Standards:
if (hidden in document)
document.addEventListener("visibilitychange", onchange);
else if ((hidden = "mozHidden") in document)
document.addEventListener("mozvisibilitychange", onchange);
else if ((hidden = "webkitHidden") in document)
document.addEventListener("webkitvisibilitychange", onchange);
else if ((hidden = "msHidden") in document)
document.addEventListener("msvisibilitychange", onchange);
// IE 9 and lower:
else if ('onfocusin' in document)
document.onfocusin = document.onfocusout = onchange;
// All others:
else
window.onpageshow = window.onpagehide
= window.onfocus = window.onblur = onchange;
function onchange (evt) {
GameAudio.settings.globalMute = !GameAudio.settings.globalMute;
if ( true === GameAudio.settings.globalMute ) {
Howler.mute();
} else {
Howler.unmute();
}
//Howler.mute();
/*
var v = 'visible', h = 'hidden',
evtMap = {
focus:v, focusin:v, pageshow:v, blur:h, focusout:h, pagehide:h
};
evt = evt || window.event;
if (evt.type in evtMap)
document.body.className = evtMap[evt.type];
else
document.body.className = this[hidden] ? "hidden" : "visible";
*/
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment