`
zhykhs
  • 浏览: 60253 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

开心网新消息

阅读更多
模拟开心网新消息的一个简单实现:
   1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">  
   2. <HTML>  
   3.  <HEAD>  
   4.   <TITLE>测试页面</TITLE>  
   5.   <script type="text/javascript">  
   6.     var dynamicMsg = null;  
   7.     function init() {  
   8.         dynamicMsg = new DynamicMessage(window.document.title, "【HI,消息】", "【     】");  
   9.     }  
  10.   
  11.     function begin() {  
  12.         dynamicMsg.initIntervalMsg();  
  13.     }  
  14.   
  15.     function end() {  
  16.         dynamicMsg.clearIntervalMsg();  
  17.     }  
  18.   
  19.     /**  
  20.       * 处理新消息提示的操作  
  21.       */  
  22.       function DynamicMessage(defaultMsg, msg, hiddenMsg) {  
  23.         this.initIntervalMsg = function() {  
  24.             this.intervalMsg = setInterval(function() {  
  25.                     if(!this.bMsg) {  
  26.                         window.document.title = msg + " - " + defaultMsg;  
  27.                         this.bMsg = true;  
  28.                     } else {  
  29.                         window.document.title = hiddenMsg + " - " + defaultMsg;  
  30.                         this.bMsg = false;  
  31.                     }         
  32.                 },   
  33.                 1000  
  34.               );  
  35.           };  
  36.             
  37.           this.clearIntervalMsg = function() {  
  38.             if(this.intervalMsg != null) {  
  39.                 clearInterval(this.intervalMsg);  
  40.                 window.document.title = defaultMsg;  
  41.                 this.bMsg = false;  
  42.             }  
  43.           };  
  44.       }  
  45.   </script>  
  46.  </HEAD>  
  47.  <BODY onload="init();">  
  48.     <center>  
  49.         <input type="button" value="begin" onclick="begin();"/>  
  50.         <input type="button" value="end" onclick="end();"/>  
  51.           
  52.   
  53.         coloryeah - 为意识增添色彩!  
  54.     </center>  
  55.  </BODY>  
  56. </HTML>  

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics