看到一些大佬的博客都是这样的
我也想呀!但是,当我扒过来后,没效果Emmm...
于是仔细看看代码,想法:这东西还要调用个api嘛,这么高端的嘛!!
又去百度找了一些,但是根本没有可以直接拿来用的。。。
哎,自己弄一个?
于是,花了(亿)点点时间折腾了下:
问题还是有的,毕竟小白只会写if(捂脸)
如果哪位路过的大佬有更好的,麻烦给我留一个咯~
<script>
var enter = '(*゜ロ゜)ノ咦!被发现啦!';
var leave = '(つ ェ ⊂)我藏好了哦!';
var clock;
var normal_title;
window.onload = function(){
if (document.visibilityState == 'hidden' && !(document.title == leave)) {
normal_title = document.title;
document.title = leave;
}
}
document.addEventListener('visibilitychange',function() {
if (document.visibilityState == 'hidden') {
if (!(document.title == enter)) {
normal_title = document.title;
}
document.title = leave;
clearTimeout(clock);
} else {
if (!(document.title == leave)) {
normal_title = document.title;
}
document.title = enter;
clock = setTimeout(function()
{
if (!(document.visibilityState == 'hidden')) {
document.title=normal_title;
}
},2500);
}
});
</script>
补充:问题解决了哦,在PJAX回调函数中加入下面这段
没有使用PJAX的就不存在这问题,只用添加上边那串就行了~
if (document.visibilityState == 'hidden' && !(document.title == leave)) {
normal_title = document.title;
document.title = leave;
}
2 条评论
花里胡哨的功能,哈~
哎呦,网站字体不错,有点萌
偶尔花哨一下,字体是[筑紫A丸ゴシック]~~