右下角弹出类似QQ或MSN消息提示

来源:互联网 发布:linux apt get 修改源 编辑:程序博客网 时间:2024/05/11 16:40
  1. <SCRIPT language=JavaScript>  
  2. <!--  
  3. /**//*  
  4. *    消息构造  
  5. */  
  6. function CLASS_MSN_MESSAGE(id,width,height,caption,title,message,target,action){  
  7.     this.id     = id;  
  8.     this.title  = title;  
  9.     this.caption= caption;  
  10.     this.message= message;  
  11.     this.target = target;  
  12.     this.action = action;  
  13.     this.width    = width?width:200;  
  14.     this.height = height?height:120;  
  15.     this.timeout= 150;  
  16.     this.speed    = 20; 
  17.     this.step    = 1; 
  18.     this.right    = screen.width -1;  
  19.     this.bottom = screen.height; 
  20.     this.left    = this.right - this.width; 
  21.     this.top    = this.bottom - this.height; 
  22.     this.timer    = 0; 
  23.     this.pause    = false;
  24.     this.close    = false;
  25.     this.autoHide    = true;
  26. }  
  27.   
  28. /**//*  
  29. *    隐藏消息方法  
  30. */  
  31. CLASS_MSN_MESSAGE.prototype.hide = function(){  
  32.     if(this.onunload()){  
  33.         var offset  = this.height>this.bottom-this.top?this.height:this.bottom-this.top; 
  34.         var me  = this;  
  35.         if(this.timer>0){   
  36.             window.clearInterval(me.timer);  
  37.         }  
  38.         var fun = function(){  
  39.             if(me.pause==false||me.close){
  40.                 var x  = me.left; 
  41.                 var y  = 0; 
  42.                 var width = me.width; 
  43.                 var height = 0; 
  44.                 if(me.offset>0){ 
  45.                     height = me.offset; 
  46.                 } 
  47.      
  48.                 y  = me.bottom - height; 
  49.      
  50.                 if(y>=me.bottom){ 
  51.                     window.clearInterval(me.timer);  
  52.                     me.Pop.hide();  
  53.                 } else { 
  54.                     me.offset = me.offset - me.step;  
  55.                 } 
  56.                 me.Pop.show(x,y,width,height);    
  57.             }             
  58.         }  
  59.         this.timer = window.setInterval(fun,this.speed)      
  60.     }  
  61. }  
  62.   
  63. /**//*  
  64. *    消息卸载事件,可以重写  
  65. */  
  66. CLASS_MSN_MESSAGE.prototype.onunload = function() {  
  67.     return true;  
  68. }  
  69. /**//*  
  70. *    消息命令事件,要实现自己的连接,请重写它  
  71. *  
  72. */  
  73. CLASS_MSN_MESSAGE.prototype.oncommand = function(){  
  74.     //this.close = true;
  75.     this.hide();  
  76.  window.open("http://www.makewing.com");
  77.    
  78. /**//*  
  79. *    消息显示方法  
  80. */  
  81. CLASS_MSN_MESSAGE.prototype.show = function(){  
  82.     var oPopup = window.createPopup(); //IE5.5+  
  83.     
  84.     this.Pop = oPopup;  
  85.   
  86.     var w = this.width;  
  87.     var h = this.height;  
  88.   
  89.     var str = "<DIV style='BORDER-RIGHT: #455690 1px solid; BORDER-TOP: #a6b4cf 1px solid; Z-INDEX: 99999; LEFT: 0px; BORDER-LEFT: #a6b4cf 1px solid; WIDTH: " + w + "px; BORDER-BOTTOM: #455690 1px solid; POSITION: absolute; TOP: 0px; HEIGHT: " + h + "px; BACKGROUND-COLOR: #c9d3f3'>"  
  90.         str += "<TABLE style='BORDER-TOP: #ffffff 1px solid; BORDER-LEFT: #ffffff 1px solid' cellSpacing=0 cellPadding=0 width='100%' bgColor=#cfdef4 border=0>"  
  91.         str += "<TR>"  
  92.         str += "<TD style='FONT-SIZE: 12px;COLOR: #0f2c8c' width=30 height=24></TD>"  
  93.         str += "<TD style='PADDING-LEFT: 4px; FONT-WEIGHT: normal; FONT-SIZE: 12px; COLOR: #1f336b; PADDING-TOP: 4px' vAlign=center width='100%'>" + this.caption + "</TD>"  
  94.         str += "<TD style='PADDING-RIGHT: 2px; PADDING-TOP: 2px' vAlign=center align=right width=19>"  
  95.         str += "<SPAN title=关闭 style='FONT-WEIGHT: bold; FONT-SIZE: 12px; CURSOR: hand; COLOR: red; MARGIN-RIGHT: 4px' id='btSysClose' >×</SPAN></TD>"  
  96.         str += "</TR>"  
  97.         str += "<TR>"  
  98.         str += "<TD style='PADDING-RIGHT: 1px;PADDING-BOTTOM: 1px' colSpan=3 height=" + (h-28) + ">"  
  99.         str += "<DIV style='BORDER-RIGHT: #b9c9ef 1px solid; PADDING-RIGHT: 8px; BORDER-TOP: #728eb8 1px solid; PADDING-LEFT: 8px; FONT-SIZE: 12px; PADDING-BOTTOM: 8px; BORDER-LEFT: #728eb8 1px solid; WIDTH: 100%; COLOR: #1f336b; PADDING-TOP: 8px; BORDER-BOTTOM: #b9c9ef 1px solid; HEIGHT: 100%'>" + this.title + "<BR><BR>"  
  100.         str += "<DIV style='WORD-BREAK: break-all' align=left><A href='javascript:void(0)' hidefocus=false id='btCommand'><FONT color=#ff0000>" + this.message + "</FONT></A> - <A href='http://www.makewing.com' hidefocus=false id='ommand'><FONT color=#ff0000>网页素材下载站</FONT></A></DIV>"  
  101.         str += "</DIV>"  
  102.         str += "</TD>"  
  103.         str += "</TR>"  
  104.         str += "</TABLE>"  
  105.         str += "</DIV>"  
  106.   
  107.     oPopup.document.body.innerHTML = str; 
  108.     
  109.   
  110.     this.offset  = 0; 
  111.     var me  = this;  
  112.     oPopup.document.body.onmouseover = function(){me.pause=true;}
  113.     oPopup.document.body.onmouseout = function(){me.pause=false;}
  114.     var fun = function(){  
  115.         var x  = me.left; 
  116.         var y  = 0; 
  117.         var width    = me.width; 
  118.         var height    = me.height; 
  119.             if(me.offset>me.height){ 
  120.                 height = me.height; 
  121.             } else { 
  122.                 height = me.offset; 
  123.             } 
  124.         y  = me.bottom - me.offset; 
  125.         if(y<=me.top){ 
  126.             me.timeout--; 
  127.             if(me.timeout==0){ 
  128.                 window.clearInterval(me.timer);  
  129.                 if(me.autoHide){
  130.                     me.hide(); 
  131.                 }
  132.             } 
  133.         } else { 
  134.             me.offset = me.offset + me.step; 
  135.         } 
  136.         me.Pop.show(x,y,width,height);    
  137.     }  
  138.   
  139.     this.timer = window.setInterval(fun,this.speed)      
  140.   
  141.      
  142.   
  143.     var btClose = oPopup.document.getElementById("btSysClose");  
  144.   
  145.     btClose.onclick = function(){  
  146.         me.close = true;
  147.         me.hide();  
  148.     }  
  149.   
  150.     var btCommand = oPopup.document.getElementById("btCommand");  
  151.     btCommand.onclick = function(){  
  152.         me.oncommand();  
  153.     }    
  154.   var ommand = oPopup.document.getElementById("ommand");  
  155.       ommand.onclick = function(){  
  156.        //this.close = true;
  157.     me.hide();  
  158.  window.open(ommand.href);
  159.     }   
  160. }  
  161. /**//* 
  162. ** 设置速度方法 
  163. **/ 
  164. CLASS_MSN_MESSAGE.prototype.speed = function(s){ 
  165.     var t = 20; 
  166.     try { 
  167.         t = praseInt(s); 
  168.     } catch(e){} 
  169.     this.speed = t; 
  170. /**//* 
  171. ** 设置步长方法 
  172. **/ 
  173. CLASS_MSN_MESSAGE.prototype.step = function(s){ 
  174.     var t = 1; 
  175.     try { 
  176.         t = praseInt(s); 
  177.     } catch(e){} 
  178.     this.step = t; 
  179.   
  180. CLASS_MSN_MESSAGE.prototype.rect = function(left,right,top,bottom){ 
  181.     try { 
  182.         this.left        = left    !=null?left:this.right-this.width; 
  183.         this.right        = right    !=null?right:this.left +this.width; 
  184.         this.bottom        = bottom!=null?(bottom>screen.height?screen.height:bottom):screen.height; 
  185.         this.top        = top    !=null?top:this.bottom - this.height; 
  186.     } catch(e){} 
  187. var MSG1 = new CLASS_MSN_MESSAGE("aa",200,120,"短消息提示:","您有1封消息","懒人图库");  
  188.     MSG1.rect(null,null,null,screen.height-50); 
  189.     MSG1.speed    = 10; 
  190.     MSG1.step    = 5; 
  191.     //alert(MSG1.top); 
  192.     MSG1.show();  
  193. //同时两个有闪烁,只能用层代替了,不过层不跨框架 
  194. //var MSG2 = new CLASS_MSN_MESSAGE("aa",200,120,"短消息提示:","您有2封消息","好的啊");  
  195. //   MSG2.rect(100,null,null,screen.height); 
  196. //    MSG2.show();  
  197. //-->  
  198. </SCRIPT>