Skip to content

Instantly share code, notes, and snippets.

@52cik
Created March 13, 2016 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 52cik/3516b68f3ba10d2a28e0 to your computer and use it in GitHub Desktop.
Save 52cik/3516b68f3ba10d2a28e0 to your computer and use it in GitHub Desktop.
页面可见性事件 - 标签页被隐藏或显示
(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