如何创建标题警报效果像Facebook? [英] How to create the title alert effect like Facebook?
本文介绍了如何创建标题警报效果像Facebook?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何创建像Facebook的闪光标题效果?意味着,当您与某人聊天并收到新消息时,标题开始在原始标题和消息之间切换,通知用户新消息的到达提供闪烁效果。
How to create flashing title effect like facebook? Means, when you are chatting with someone and a new message is received, a title starts to switch between the original title and a message informing user of the arrival of new message giving a flashing effect.
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.
这篇关于如何创建标题警报效果像Facebook?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文