前言

如你所见,我的博客的浏览器标签页是会动的 ヾ(≧ ▽ ≦)ゝ

当处于非活动状态之后标题会改变。

教程

在网页HTML的</head>之前或是</body>之前引入:

<script type="text/javascript" src="/js/title.js"></script>

title.js内容如下:

document.addEventListener("visibilitychange", function () {
if (document.visibilityState == "hidden") {
normal_title = document.title;
let titleState = 0;
titleInterval = setInterval(() => {
document.title = titleState == 2 ? " Ciallo~ (∠・ω< )⌒☆!" : titleState == 1 ? "♪~(‾◡◝) 啥时再来看看我 . . ." : normal_title;
titleState = titleState == 2 ? 0 : titleState + 1;
}, 8000);
} else {
if (titleInterval) {
clearInterval(titleInterval);
document.title = normal_title;
}
}
});

就可以做到切换了!

其中8000是轮换毫秒数。

懒得写case了所以直接套了两个三元运算符…