我有一个JavaScript聊天。当用户收到消息时,我希望the title闪烁,直到它变为 Activity 状态为止。 (例如Gmail Talk)
例如:
My website
My website
和User says: bla bla
My website
如何使用jQuery实现呢?
到目前为止我尝试过的内容:(闪烁不会停止播放)
var isOldTitle = true;
var oldTitle = "oldTitle";
var newTitle = "newTitle";
function changeTitle() {
document.title = isOldTitle ? oldTitle : newTitle;
isOldTitle = !isOldTitle;
setTimeout(changeTitle, 700);
}
changeTitle();
最佳答案
完整解决方案:
var isOldTitle = true;
var oldTitle = "oldTitle";
var newTitle = "newTitle";
var interval = null;
function changeTitle() {
document.title = isOldTitle ? oldTitle : newTitle;
isOldTitle = !isOldTitle;
}
interval = setInterval(changeTitle, 700);
$(window).focus(function () {
clearInterval(interval);
$("title").text(oldTitle);
});