js实现页面title闪烁
更新于 阅读 15 次
在页面收到消息之后需要通过titile闪烁的方式来提示用户,可以通过js来实现
class MessageNotice { timer = undefined; title = document.title; count = 0; show() { this.timer = setInterval(() => { // 偶数显示提示 if (this.count % 2 === 0) { document.title = "【新消息】" + this.title; } else { document.title = "【 】" + this.title; } this.count++; }, 500) } stop() { if (this.timer) { clearInterval(this.timer ); this.timer = null; this.count = 0; document.title = this.title; } } } const messageNotice = new MessageNotice(); // 开始执行 messageNotice.show(); // 停止 //messageNotice.stop();