Created
March 13, 2016 12:32
-
-
Save 52cik/3516b68f3ba10d2a28e0 to your computer and use it in GitHub Desktop.
页面可见性事件 - 标签页被隐藏或显示
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
(function(document) { // title提示 | |
var titleTime; | |
var oldTitle = document.title; | |
var shortcut = document.getElementById('shortcut'); | |
document.addEventListener('visibilitychange', function() { | |
if (document.hidden) { | |
document.title = '(●—●)咦,去哪儿啊?'; | |
clearTimeout(titleTime); | |
shortcut.href = 'images/fail.ico'; | |
} else { | |
document.title = '(/≧▽≦/)欢迎回来! - ' + oldTitle; | |
shortcut.href = 'images/favicon.ico'; | |
titleTime = setTimeout(function() { | |
document.title = oldTitle; | |
}, 2e3); | |
} | |
}) | |
})(document); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment