DDR爱好者之家 Design By 杰米
本文实例讲述了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程序设计有所帮助。
DDR爱好者之家 Design By 杰米
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
DDR爱好者之家 Design By 杰米
暂无评论...
更新日志
2024年11月29日
2024年11月29日
- 凤飞飞《我们的主题曲》飞跃制作[正版原抓WAV+CUE]
- 刘嘉亮《亮情歌2》[WAV+CUE][1G]
- 红馆40·谭咏麟《歌者恋歌浓情30年演唱会》3CD[低速原抓WAV+CUE][1.8G]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[320K/MP3][193.25MB]
- 【轻音乐】曼托凡尼乐团《精选辑》2CD.1998[FLAC+CUE整轨]
- 邝美云《心中有爱》1989年香港DMIJP版1MTO东芝首版[WAV+CUE]
- 群星《情叹-发烧女声DSD》天籁女声发烧碟[WAV+CUE]
- 刘纬武《睡眠宝宝竖琴童谣 吉卜力工作室 白噪音安抚》[FLAC/分轨][748.03MB]
- 理想混蛋《Origin Sessions》[320K/MP3][37.47MB]
- 公馆青少年《我其实一点都不酷》[320K/MP3][78.78MB]
- 群星《情叹-发烧男声DSD》最值得珍藏的完美男声[WAV+CUE]
- 群星《国韵飘香·贵妃醉酒HQCD黑胶王》2CD[WAV]
- 卫兰《DAUGHTER》【低速原抓WAV+CUE】
- 公馆青少年《我其实一点都不酷》[FLAC/分轨][398.22MB]
- ZWEI《迟暮的花 (Explicit)》[320K/MP3][57.16MB]