提供类似MSN消息框

 
  1. <HTML><HEAD>    
  2.   
  3. <SCRIPT language=JavaScript>     
  4.   
  5. <!--     
  6.   
  7.      
  8.   
  9. /**//*    
  10. **    ==================================================================================================    
  11. **    类名:CLASS_MSN_MESSAGE    
  12. **    功能:提供类似MSN消息框    
  13. **    示例:    
  14.     ---------------------------------------------------------------------------------------------------    
  15.     
  16.             var MSG = new CLASS_MSN_MESSAGE("aa",200,120,"短消息提示:","您有1封消息","今天请我吃饭哈");    
  17.                 MSG.show();    
  18.     
  19.     ---------------------------------------------------------------------------------------------------    
  20. **    作者:ttyp    
  21. **    邮件:ttyp@21cn.com    
  22. **    日期:2005-3-18    
  23. **    ==================================================================================================    
  24. **/     
  25.   
  26.      
  27.   
  28.      
  29.   
  30. /**//*    
  31.  *    消息构造    
  32.  */     
  33.   
  34. function CLASS_MSN_MESSAGE(id,width,height,caption,title,message,target,action){     
  35.   
  36.     this.id     = id;     
  37.   
  38.     this.title  = title;     
  39.   
  40.     this.caption= caption;     
  41.   
  42.     this.message= message;     
  43.   
  44.     this.target = target;     
  45.   
  46.     this.action = action;     
  47.   
  48.     this.width    = width?width:200;     
  49.   
  50.     this.height = height?height:120;     
  51.   
  52.     this.timeout= 150;     
  53.   
  54.     this.speed    = 20;    
  55.   
  56.     this.step    = 1;    
  57.   
  58.     this.right    = screen.width -1;     
  59.   
  60.     this.bottom = screen.height;    
  61.   
  62.     this.left    = this.right - this.width;    
  63.   
  64.     this.top    = this.bottom - this.height;    
  65.   
  66.     this.timer    = 0;    
  67.   
  68.     this.pause    = false;   
  69.   
  70.     this.close    = false;   
  71.   
  72.     this.autoHide    = true;   
  73.   
  74. }     
  75.   
  76.      
  77.   
  78. /**//*    
  79.  *    隐藏消息方法    
  80.  */     
  81.   
  82. CLASS_MSN_MESSAGE.prototype.hide = function(){     
  83.   
  84.     if(this.onunload()){     
  85.   
  86.   
  87.   
  88.         var offset  = this.height>this.bottom-this.top?this.height:this.bottom-this.top;    
  89.   
  90.         var me  = this;     
  91.   
  92.     
  93.   
  94.         if(this.timer>0){      
  95.   
  96.             window.clearInterval(me.timer);     
  97.   
  98.         }     
  99.   
  100.     
  101.   
  102.         var fun = function(){     
  103.   
  104.             if(me.pause==false||me.close){   
  105.   
  106.                 var x  = me.left;    
  107.   
  108.                 var y  = 0;    
  109.   
  110.                 var width = me.width;    
  111.   
  112.                 var height = 0;    
  113.   
  114.                 if(me.offset>0){    
  115.   
  116.                     height = me.offset;    
  117.   
  118.                 }    
  119.   
  120.         
  121.   
  122.                 y  = me.bottom - height;    
  123.   
  124.         
  125.   
  126.                 if(y>=me.bottom){    
  127.   
  128.                     window.clearInterval(me.timer);     
  129.   
  130.                     me.Pop.hide();     
  131.   
  132.                 } else {    
  133.   
  134.                     me.offset = me.offset - me.step;     
  135.   
  136.                 }    
  137.   
  138.                 me.Pop.show(x,y,width,height);       
  139.   
  140.             }                
  141.   
  142.         }     
  143.   
  144.     
  145.   
  146.         this.timer = window.setInterval(fun,this.speed)         
  147.   
  148.     }     
  149.   
  150. }     
  151.   
  152.      
  153.   
  154. /**//*    
  155.  *    消息卸载事件,可以重写    
  156.  */     
  157.   
  158. CLASS_MSN_MESSAGE.prototype.onunload = function() {     
  159.   
  160.     return true;     
  161.   
  162. }     
  163.   
  164. /**//*    
  165.  *    消息命令事件,要实现自己的连接,请重写它    
  166.  *    
  167.  */     
  168.   
  169. CLASS_MSN_MESSAGE.prototype.oncommand = function(){     
  170.   
  171.     this.close = true;   
  172.   
  173.     this.hide();     
  174.   
  175. }     
  176.   
  177.      
  178.   
  179. /**//*    
  180.  *    消息显示方法    
  181.  */     
  182.   
  183. CLASS_MSN_MESSAGE.prototype.show = function(){     
  184.   
  185.   
  186.   
  187.     var oPopup = window.createPopup(); //IE5.5+     
  188.   
  189.        
  190.   
  191.     this.Pop = oPopup;     
  192.   
  193.      
  194.   
  195.     var w = this.width;     
  196.   
  197.     var h = this.height;     
  198.   
  199.      
  200.   
  201.     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'>"     
  202.   
  203.         str += "<TABLE style='BORDER-TOP: #ffffff 1px solid; BORDER-LEFT: #ffffff 1px solid' cellSpacing=0 cellPadding=0 width='100%' bgColor=#cfdef4 border=0>"     
  204.   
  205.         str += "<TR>"     
  206.   
  207.         str += "<TD style='FONT-SIZE: 12px;COLOR: #0f2c8c' width=30 height=24></TD>"     
  208.   
  209.         str += "<TD style='PADDING-LEFT: 4px; FONT-WEIGHT: normal; FONT-SIZE: 12px; COLOR: #1f336b; PADDING-TOP: 4px' vAlign=center width='100%'>" + this.caption + "</TD>"     
  210.   
  211.         str += "<TD style='PADDING-RIGHT: 2px; PADDING-TOP: 2px' vAlign=center align=right width=19>"     
  212.   
  213.         str += "<SPAN title=关闭 style='FONT-WEIGHT: bold; FONT-SIZE: 12px; CURSOR: hand; COLOR: red; MARGIN-RIGHT: 4px' id='btSysClose' >×</SPAN></TD>"     
  214.   
  215.         str += "</TR>"     
  216.   
  217.         str += "<TR>"     
  218.   
  219.         str += "<TD style='PADDING-RIGHT: 1px;PADDING-BOTTOM: 1px' colSpan=3 height=" + (h-28) + ">"     
  220.   
  221.         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>"     
  222.   
  223.         str += "<DIV style='WORD-BREAK: break-all' align=left><A href='javascript:void(0)' hidefocus=true id='btCommand'><FONT color=#ff0000>" + this.message + "</FONT></A></DIV>"     
  224.   
  225.         str += "</DIV>"     
  226.   
  227.         str += "</TD>"     
  228.   
  229.         str += "</TR>"     
  230.   
  231.         str += "</TABLE>"     
  232.   
  233.         str += "</DIV>"     
  234.   
  235.      
  236.   
  237.     oPopup.document.body.innerHTML = str;    
  238.   
  239.        
  240.   
  241.      
  242.   
  243.     this.offset  = 0;    
  244.   
  245.     var me  = this;     
  246.   
  247.   
  248.   
  249.     oPopup.document.body.onmouseover = function(){me.pause=true;}   
  250.   
  251.     oPopup.document.body.onmouseout = function(){me.pause=false;}   
  252.   
  253.   
  254.   
  255.     var fun = function(){     
  256.   
  257.         var x  = me.left;    
  258.   
  259.         var y  = 0;    
  260.   
  261.         var width    = me.width;    
  262.   
  263.         var height    = me.height;    
  264.   
  265.     
  266.   
  267.             if(me.offset>me.height){    
  268.   
  269.                 height = me.height;    
  270.   
  271.             } else {    
  272.   
  273.                 height = me.offset;    
  274.   
  275.             }    
  276.   
  277.     
  278.   
  279.         y  = me.bottom - me.offset;    
  280.   
  281.         if(y<=me.top){    
  282.   
  283.             me.timeout--;    
  284.   
  285.             if(me.timeout==0){    
  286.   
  287.                 window.clearInterval(me.timer);     
  288.   
  289.                 if(me.autoHide){   
  290.   
  291.                     me.hide();    
  292.   
  293.                 }   
  294.   
  295.             }    
  296.   
  297.         } else {    
  298.   
  299.             me.offset = me.offset + me.step;    
  300.   
  301.         }    
  302.   
  303.         me.Pop.show(x,y,width,height);       
  304.   
  305.     
  306.   
  307.     }     
  308.   
  309.      
  310.   
  311.     this.timer = window.setInterval(fun,this.speed)         
  312.   
  313.      
  314.   
  315.         
  316.   
  317.      
  318.   
  319.     var btClose = oPopup.document.getElementById("btSysClose");     
  320.   
  321.      
  322.   
  323.     btClose.onclick = function(){     
  324.   
  325.         me.close = true;   
  326.   
  327.         me.hide();     
  328.   
  329.     }     
  330.   
  331.      
  332.   
  333.     var btCommand = oPopup.document.getElementById("btCommand");     
  334.   
  335.     btCommand.onclick = function(){     
  336.   
  337.         me.oncommand();     
  338.   
  339.     }       
  340.   
  341. }     
  342.   
  343. /**//*   
  344. ** 设置速度方法   
  345. **/    
  346.   
  347. CLASS_MSN_MESSAGE.prototype.speed = function(s){    
  348.   
  349.     var t = 20;    
  350.   
  351.     try {    
  352.   
  353.         t = praseInt(s);    
  354.   
  355.     } catch(e){}    
  356.   
  357.     this.speed = t;    
  358.   
  359. }    
  360.   
  361. /**//*   
  362. ** 设置步长方法   
  363. **/    
  364.   
  365. CLASS_MSN_MESSAGE.prototype.step = function(s){    
  366.   
  367.     var t = 1;    
  368.   
  369.     try {    
  370.   
  371.         t = praseInt(s);    
  372.   
  373.     } catch(e){}    
  374.   
  375.     this.step = t;    
  376.   
  377. }    
  378.   
  379.      
  380.   
  381. CLASS_MSN_MESSAGE.prototype.rect = function(left,right,top,bottom){    
  382.   
  383.     try {    
  384.   
  385.         this.left        = left    !=null?left:this.right-this.width;    
  386.   
  387.         this.right        = right    !=null?right:this.left +this.width;    
  388.   
  389.         this.bottom        = bottom!=null?(bottom>screen.height?screen.height:bottom):screen.height;    
  390.   
  391.         this.top        = top    !=null?top:this.bottom - this.height;    
  392.   
  393.     } catch(e){}    
  394.   
  395. }    
  396.   
  397. var MSG1 = new CLASS_MSN_MESSAGE("aa",200,120,"短消息提示:","您有1封消息","今天请我吃饭哈");     
  398.   
  399.     MSG1.rect(null,null,null,screen.height-50);    
  400.   
  401.     MSG1.speed    = 30;    
  402.   
  403.     MSG1.step    = 5;    
  404.   
  405.     //alert(MSG1.top);    
  406.   
  407.     MSG1.show();     
  408.   
  409.     
  410.   
  411. //同时两个有闪烁,只能用层代替了,不过层不跨框架    
  412.   
  413. //var MSG2 = new CLASS_MSN_MESSAGE("aa",200,120,"短消息提示:","您有2封消息","好的啊");     
  414.   
  415. //   MSG2.rect(100,null,null,screen.height);    
  416.   
  417. //    MSG2.show();     
  418.   
  419. //-->     
  420.   
  421. </SCRIPT>    
  422.   
  423.     
  424.   
  425. <META content="MSHTML 6.00.2800.1106" name=GENERATOR></HEAD>    
  426.   
  427. <BODY></BODY></HTML>   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值