本文实例讲述了JS实现消息来时让网页标题闪动效果的方法。分享给大家供大家参考,具体如下:
<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>无标题页</title> <script> var g_blinkid = 0; var g_blinkswitch = 0; var g_blinktitle = document.title; var g_onlineuser = ""; var g_sysmsg_sound = null; var g_newmsg_sound = null; var g_app_num = 0; var g_appnum = 0; var g_bappmore = false; var g_inputtime = 0; function blinkNewMsg() { document.title = g_blinkswitch % 2==0 "【 】 - " + g_blinktitle : "【新消息】 - " + g_blinktitle; g_blinkswitch++; } g_blinkid = setInterval(blinkNewMsg, 1000); function stopBlinkNewMsg() { if (g_blinkid) { clearInterval(g_blinkid); g_blinkid = 0; document.title = g_blinktitle; } } </script> </head> <body> <form id="form1" runat="server"> <div> <input id="Button1" type="button" value="button" onclick="stopBlinkNewMsg();" /> </div> </form> </body> </html>
参考开心网的head-26.js
var g_blinkid = 0; var g_blinkswitch = 0; var g_blinktitle = document.title; var g_onlineuser = ""; var g_sysmsg_sound = null; var g_newmsg_sound = null; var g_app_num = 0; var g_appnum = 0; var g_bappmore = false; var g_inputtime = 0; function blinkNewMsg() { var now = new Date(); var nowtime = now.getTime(); if(nowtime - g_inputtime > 5000) { document.title = g_blinkswitch % 2 "【 】 - " + g_blinktitle : "【新消息】 - " + g_blinktitle; } g_blinkswitch++; } function blinkOnline() { document.title = g_blinkswitch % 2 "○" + g_onlineuser + " 上线了 - " + g_blinktitle : "●" + g_onlineuser + " 上线了 - " + g_blinktitle; g_blinkswitch++; if (g_blinkswitch > 10) { stopBlinkNewMsg(); } } function checkNewMsg() { var url = "/home/newmsg.php"; var pars = ""; var myAjax = new Ajax.Request(url, {method: "post", parameters: pars, onComplete: function (req) { checkNewMsgShow(req); } }); } function stopBlinkNewMsg() { if (g_blinkid) { clearInterval(g_blinkid); g_blinkid = 0; $("head_msgdiv").style.display = "none"; document.title = g_blinktitle; } } var g_oldmsg = g_oldsysmsg = g_oldbbs = g_oldbbsreply = g_oldcomment = g_oldreply = 0; function checkNewMsgShow(req) { var r = req.responseText; stopBlinkNewMsg(); setTimeout(checkNewMsg, 60000); eval ("r="+r); var a_msglist = new Array("msg", "sysmsg", "bbs", "bbsreply", "comment", "reply"); if(r.notice == "1") { var forbidsound = parseInt(r.forbidsound); if (!forbidsound) { for (i=0; i<a_msglist.length; i++) { if ($("body_" + a_msglist[i] + "_num")) { var c = parseInt($("body_" + a_msglist[i] + "_num").innerHTML); eval("g_old" + a_msglist[i] + "=c;"); } } var newmsg = parseInt(r.msg) + parseInt(r.bbs) + parseInt(r.bbsreply) + parseInt(r.comment) + parseInt(r.reply); var sysmsg = parseInt(r.sysmsg); var newchange = (parseInt(r.msg) - g_oldmsg) || (parseInt(r.bbs) - g_oldbbs) || (parseInt(r.bbsreply) - g_oldbbsreply) || (parseInt(r.comment) - g_oldcomment) || (parseInt(r.reply) - g_oldreply); var syschange = (parseInt(r.sysmsg) - g_oldsysmsg); for (i=0; i<a_msglist.length; i++) { eval("g_old" + a_msglist[i] + "=parseInt(r." + a_msglist[i] + ");"); } if (newmsg && newchange) { if (g_newmsg_sound == null) { g_newmsg_sound = new SWFObject("http://img.kaixin001.com.cn/i2/newmsg_sound.1.0.swf", "newmsg_sound_swf", "1", "1", "8", "#ffffff", true); g_newmsg_sound.addParam("allowscriptaccess", "always"); g_newmsg_sound.addParam("wmode", "opaque"); g_newmsg_sound.addParam("menu", "false"); g_newmsg_sound.addVariable("autoplay","0"); } g_newmsg_sound.write("head_msgsound_div"); } else if (sysmsg && syschange) { if (g_sysmsg_sound == null) { g_sysmsg_sound = new SWFObject("http://img.kaixin001.com.cn/i2/sysmsg_sound.1.0.swf", "sysmsg_sound_swf", "1", "1", "8", "#ffffff", true); g_sysmsg_sound.addParam("allowscriptaccess", "always"); g_sysmsg_sound.addParam("wmode", "opaque"); g_sysmsg_sound.addParam("menu", "false"); g_sysmsg_sound.addVariable("autoplay","0"); } g_sysmsg_sound.write("head_msgsound_div"); } } $("head_msgdiv").style.display = "block"; g_blinkid = setInterval(blinkNewMsg, 1000); } else if (0 && r.online.length) { g_blinkswitch = 0; g_onlineuser = r.online; g_blinkid = setInterval(blinkOnline, 500); } for (i=0; i<a_msglist.length; i++) { if (!parseInt(r[a_msglist[i]])) { $("head_" + a_msglist[i] + "_num").innerHTML = ""; if ($("body_" + a_msglist[i] + "_num")) { $("body_" + a_msglist[i] + "_num").className = "ql2"; $("body_" + a_msglist[i] + "_num").innerHTML = "0条新"; } } else { $("head_" + a_msglist[i] + "_num").innerHTML = "(" + r[a_msglist[i]] + ")"; if ($("body_" + a_msglist[i] + "_num")) { $("body_" + a_msglist[i] + "_num").className = "cr"; $("body_" + a_msglist[i] + "_num").innerHTML = r[a_msglist[i]] + "条新"; } if (a_msglist[i] == "msg") { if ('function' == typeof(msg_view_checkNewMsg)) { msg_view_checkNewMsg(); }; } } } } function outputHead() { var v_html = '<div id="head">' +' <div class="hd">' +' <div class="h1 wl1" style="margin-top:3px;">' +' <div style="padding-left:18px;"><a href="/" class="cf" title="开心网"><img src="/UploadFiles/2021-04-02/kaixinlogo.gif">更多关于JavaScript相关内容感兴趣的读者可查看本站专题:《JavaScript中ajax操作技巧总结》、《JavaScript切换特效与技巧总结》、《JavaScript查找算法技巧总结》、《JavaScript动画特效与技巧汇总》、《JavaScript错误与调试技巧总结》、《JavaScript数据结构与算法技巧总结》、《JavaScript遍历算法与技巧总结》及《JavaScript数学运算用法总结》
希望本文所述对大家JavaScript程序设计有所帮助。
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“JS实现消息来时让网页标题闪动效果的方法”评论...
更新动态
2024年11月15日
2024年11月15日
- 群星《2024好听新歌14》十倍音质 U盘音乐 [WAV分轨][966M]
- s14全球总决赛T1战队队员都有谁 LOLs14全球总决赛T1战队介绍
- 英雄联盟faker身价有10亿吗 英雄联盟faker身价介绍一览
- faker大魔王称号怎么来的 faker大魔王称号来源介绍
- PS5 Pro上的蒂法更美了!博主盛赞新机1000%值得购买
- 腾讯互娱再离职一员大将!或因供应商贪腐
- Ayaneo3游戏掌机预热:旗舰定位、造型圆润自带底键
- 动力火车.1999-背叛情歌【上华】【WAV+CUE】
- 刘力扬.2019-Neon.Lit虹【摩登天空】【FLAC分轨】
- 群星.2002-恋爱物语情歌对唱精选2CD(引进版)【滚石】【WAV+CUE】
- 群星《闽南情24K德国HD金碟》2CD[WAV+CUE]
- 周传雄《恋人创世纪》环球唱片[WAV+CUE]
- 关淑怡-《真假情话K2HD》(日本压制)【WAV+CUE】
- 王菲 -《Faye Wong》雨果LPCD45 [WAV+分轨][1G]
- 陈百强《世纪10星·永恒篇》环球[WAV+CUE][1G]