gpt4 book ai didi

javascript - 如何制作类似Facebook的标题提醒效果?

转载 作者:可可西里 更新时间:2023-11-01 01:45:18 25 4
gpt4 key购买 nike

如何制作类似facebook的闪动标题效果?意思是,当您与某人聊天并收到一条新消息时,标题开始在原始标题和通知用户新消息到达的消息之间切换,从而产生闪烁效果。

AdrianoKF 的解释:

Notice the window title cycling between something like "New message from Foo Bar" and the regular one after receiving a new chat message.

最佳答案

代码:

(function () {

var original = document.title;
var timeout;

window.flashTitle = function (newMsg, howManyTimes) {
function step() {
document.title = (document.title == original) ? newMsg : original;

if (--howManyTimes > 0) {
timeout = setTimeout(step, 1000);
};
};

howManyTimes = parseInt(howManyTimes);

if (isNaN(howManyTimes)) {
howManyTimes = 5;
};

cancelFlashTitle(timeout);
step();
};

window.cancelFlashTitle = function () {
clearTimeout(timeout);
document.title = original;
};

}());

用法:

flashTitle("New Message from Matt Lunn");

……或者……

flashTitle("New Message from John Smith", 10); // toggles it 10 times.

关于javascript - 如何制作类似Facebook的标题提醒效果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3381462/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com