zoukankan      html  css  js  c++  java
  • 类似msn的弹出窗口控件

    1.以前看到别人写类似的文章,不过都是js的,想用得方便点,要改好多东东,觉得有点烦,但是我也不想看到页面里有n多的js,总之一句就是烦那些js.正好最近看到可以把js 放到dll里面,于是就有了封装的念头。
    2.先看一下别人的js吧,写的很好。

      1 /**//*  
      2 *    消息构造  
      3 */  
      4 function CLASS_MSN_MESSAGE(id,width,height,message,imgpath){  
      5     this.id     = id;  
      6     this.imgpath  = imgpath;  
      7     //
      8     this.message= message;  
      9     //
     10     //
     11     this.width    = width?200;  
     12     this.height = height?height:120;  
     13     this.timeout= 150;  
     14     this.speed    = 20
     15     this.step    = 1
     16     this.right    = screen.width -1;  
     17     this.bottom = screen.height; 
     18     this.left    = this.right - this.width; 
     19     this.top    = this.bottom - this.height; 
     20     this.timer    = 0
     21     this.pause    = false;
     22     this.close    = false;
     23     this.autoHide    = true;
     24 }  
     25   
     26 /**//*  
     27 *    隐藏消息方法  
     28 */  
     29 CLASS_MSN_MESSAGE.prototype.hide = function(){  
     30     if(this.onunload()){  
     31 
     32         var offset  = this.height>this.bottom-this.top?this.height:this.bottom-this.top; 
     33         var me  = this;  
     34 
     35         if(this.timer>0){   
     36             window.clearInterval(me.timer);  
     37         }  
     38 
     39         var fun = function(){  
     40             if(me.pause==false||me.close){
     41                 var x  = me.left; 
     42                 var y  = 0
     43                 var width = me.width; 
     44                 var height = 0
     45                 if(me.offset>0){ 
     46                     height = me.offset; 
     47                 } 
     48      
     49                 y  = me.bottom - height; 
     50      
     51                 if(y>=me.bottom){ 
     52                     window.clearInterval(me.timer);  
     53                     me.Pop.hide();  
     54                 } else { 
     55                     me.offset = me.offset - me.step;  
     56                 } 
     57                 me.Pop.show(x,y,width,height);    
     58             }             
     59         }  
     60 
     61         this.timer = window.setInterval(fun,this.speed)      
     62     }  
     63 }  
     64   
     65 /**//*  
     66 *    消息卸载事件,可以重写  
     67   */ 
     68 CLASS_MSN_MESSAGE.prototype.onunload = function() {  
     69     return true;  
     70 
     71 /**//*  
     72 *    消息命令事件,要实现自己的连接,请重写它  
     73 *  
     74 */  
     75 CLASS_MSN_MESSAGE.prototype.oncommand = function(){  
     76     //this.close = true;
     77     this.hide();  
     78     
     79    
     80 
     81 /**//*  
     82 *    消息显示方法  
     83 */  
     84 CLASS_MSN_MESSAGE.prototype.show = function(){  
     85 
     86     var oPopup = window.createPopup(); //IE5.5+  
     87     
     88     this.Pop = oPopup;  
     89   
     90     var w = this.width;  
     91     var h = this.height;  
     92   
     93    
     94         //
     95         var str = "<div style='WIDTH: " + w + "px;  HEIGHT: " + h + "px; border: solid 1px #9f1010; padding:2px; filter:progid:DXImageTransform.Microsoft.Gradient(startColorStr=#ffffff endColorStr=#f9f3e4, gradientType=0); '>"
     96             str+="<table cellpadding='0' cellspacing='0' border='0' width='100%'>"
     97             str+="<tr>"
     98             str+="   <td  style='background-attachment: fixed; background-image: url("+this.imgpath+"/info_01.gif); background-repeat: repeat-x'>"
     99             str+="      <table cellpadding='0' cellspacing='0' border='0' width='100%'>";
    100             str+="      <tr>"
    101             str+="      <td align='left'>"
    102             str+="           <img src='"+this.imgpath+"/info_02.gif' /></td>"
    103             str+="      <td align='right'>"
    104             str+="           <img id='btSysClose' src='"+this.imgpath+"/info_03.gif' /></td>"
    105             str+="      </tr>"
    106             str+="      </table>"
    107                    
    108             str+="   </td>"
    109             str+="</tr>"
    110             str+="<tr>"
    111             str+="    <td>"
    112             str+="        <table cellpadding='0' border='0' cellspacing='0' width='100%'>"
    113             str+="        <tr>"
    114             str+="       <td align='left' style='92px'>"
    115             str+="         <img src='"+this.imgpath+"/info_04.gif' />"
    116             str+="       </td>"
    117             str+="       <td valign='top'><span id='btCommand' style='font-size: 10pt; font-family: 宋体'>"+this.message+"</span>"
    118             str+="           </td>"
    119             str+="      </tr>"
    120             str+="       </table>"
    121             str+="        </td>"
    122             str+="</tr>"
    123             str+="</table>"
    124             str+="</div>"
    125         
    126         //
    127   
    128   
    129     oPopup.document.body.innerHTML = str; 
    130     
    131   
    132     this.offset  = 0
    133     var me  = this;  
    134 
    135     oPopup.document.body.onmouseover = function(){me.pause=true;}
    136     oPopup.document.body.onmouseout = function(){me.pause=false;}
    137 
    138     var fun = function(){  
    139         var x  = me.left; 
    140         var y  = 0
    141         var width    = me.width; 
    142         var height    = me.height; 
    143 
    144             if(me.offset>me.height){ 
    145                 height = me.height; 
    146             } else { 
    147                 height = me.offset; 
    148             } 
    149 
    150         y  = me.bottom - me.offset; 
    151         if(y<=me.top){ 
    152             me.timeout--
    153             if(me.timeout==0){ 
    154                 window.clearInterval(me.timer);  
    155                 if(me.autoHide){
    156                     me.hide(); 
    157                 }
    158             } 
    159         } else { 
    160             me.offset = me.offset + me.step; 
    161         } 
    162         me.Pop.show(x,y,width,height);    
    163 
    164     }  
    165   
    166     this.timer = window.setInterval(fun,this.speed)      
    167   
    168      
    169   
    170     var btClose = oPopup.document.getElementById("btSysClose");  
    171   
    172     btClose.onclick = function(){  
    173         me.close = true;
    174         me.hide();  
    175     }  
    176   
    177     var btCommand = oPopup.document.getElementById("btCommand");  
    178     btCommand.onclick = function(){  
    179         me.oncommand();  
    180     }    
    181 ** 设置速度方法 
    182 **/ 
    183 CLASS_MSN_MESSAGE.prototype.speed = function(s){ 
    184     var t = 20
    185     try { 
    186         t = praseInt(s); 
    187     } catch(e){} 
    188     this.speed = t; 
    189 
    190 /**//* 
    191 ** 设置步长方法 
    192 **/ 
    193 CLASS_MSN_MESSAGE.prototype.step = function(s){ 
    194     var t = 1
    195     try { 
    196         t = praseInt(s); 
    197     } catch(e){} 
    198     this.step = t; 
    199 
    200   
    201 CLASS_MSN_MESSAGE.prototype.rect = function(left,right,top,bottom){ 
    202     try { 
    203         this.left        = left    !=null?left:this.right-this.width; 
    204         this.right        = right    !=null?right:this.left +this.width; 
    205         this.bottom        = bottom!=null?(bottom>screen.height?screen.height:bottom):screen.height; 
    206         this.top        = top    !=null?top:this.bottom - this.height; 
    207     } catch(e){} 
    208 

    写的还很经典的。有时候自己看到别人的代码觉得能看懂,也不什么,但是要是能写出来就不那么容易了。就是眼高手低的问题。
    3.分享一下我的代码。(少得很)
     1 using System;
     2 using System.Collections.Generic;
     3 using System.ComponentModel;
     4 using System.Text;
     5 using System.Web;
     6 using System.Web.UI;
     7 using System.Web.UI.WebControls;
     8 
     9 [assembly: WebResource("PopWin.js""application/x-javascript")]
    10 
    11 namespace HBControl
    12 {
    13     [DefaultProperty("Text")]
    14     [ToolboxData("<{0}:HBPopWin runat=server></{0}:HBPopWin>")]
    15     public class HBPopWin : WebControl
    16     {
    17         protected override void OnPreRender(EventArgs e)
    18         {
    19             if (this.Page != null)
    20             {
    21                 ClientScriptManager mgr = this.Page.ClientScript;
    22                 mgr.RegisterClientScriptResource(typeof(HBPopWin), "PopWin.js");
    23             }
    24             base.OnPreRender(e);
    25         }
    26     }
    27 }

    要想把js文件编译到dll中,还需要进行设置一下。就是把你的xxx.csproj用记事本打开,
    (1)找到
    <RootNamespace>xxxxx</RootNamespace>结点
    把结点RootNamespace里的'xxxxx'去掉
    (2)找到js文件点右键,把'生成操作"选择为:嵌入的资源.就可以了
    4.最后附加一下源码
    /Files/HeroBeast/HBControl.rar

  • 相关阅读:
    MySql使用游标Cursor循环(While)更新数据
    初试TinyIoCContainer笔记
    用Razor做静态页面生成器
    在CentOS6.5上安装MariaDB
    mono的远程调试
    mono3.2.3+Jexus5.5+openSuSE13.1的asp.net
    mono3.2和monodevelop4.0在ubuntu12.04上两天的苦战
    第一节知识点:.net与c#的概念
    支付宝支付功能(使用支付宝sdk)
    vs2017/vs2019 去掉 单击aspx文件预览页面
  • 原文地址:https://www.cnblogs.com/HeroBeast/p/751272.html
Copyright © 2011-2022 走看看