`
lbyzx123
  • 浏览: 468140 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

弹出层窗口,并实现拖拽效果

阅读更多

<style>
#div1 {
 float: left;
 padding: 5px;
 margin: 10px;
 background: #FFF;
 border: 1px solid #c51100;
 width: 250px;
 height:480px;
 }
#div2{
 float: left;
 padding: 5px;
 margin: 10px;
 background: #FFF;
 border: 1px solid #c51100;
 width: 250px;
 height:480px;
 }

</style>
<DIV id=ctl04_ddlSalesMan style="Z-INDEX: 3; WIDTH:200px" value text>
<INPUT id=ctl04_ddlSalesMan_valueField type=hidden name=ctl04_ddlSalesMan_valueField>
<TABLE id=ctl04_ddlSalesMan_tblRefControl cellSpacing=0 cellPadding=0 width="100%" border=0 unselectable="on">
 <TBODY>
 <TR>
  <TD unselectable="on">
   <INPUT id=ctl04_ddlSalesMan_textField style="WIDTH: 100%" name=ctl04_ddlSalesMan_textField autocomplete="off">
  </TD>
  <TD width=34 unselectable="on">
   <IMG id=ctl04_ddlSalesMan_imgNew style="WIDTH: 17px; HEIGHT: 16px" src="images/RefControlNew.gif"><IMG id=ctl04_ddlSalesMan_img style="WIDTH: 17px; HEIGHT: 16px" src="images/RefControlSearch.gif" onclick='popDiv();'>
  </TD>
 </TR>
 </TBODY>
</TABLE>
</DIV>
 <script>
   /**
   *弹出层
   */
   function popDiv()
   {
    var msgw,msgh,bordercolor;
    msgw=600;//提示窗口的宽度
    msgh=500;//提示窗口的高度
    titleheight=25 //提示窗口标题高度
    bordercolor="#c51100";//提示窗口的边框颜色
    titlecolor="#c51100";//提示窗口的标题颜色    
    var sWidth,sHeight;
    sWidth=screen.width;
    sHeight=screen.height;
    //创建阴影层    
    var bgObj=document.createElement("div");
    bgObj.setAttribute('id','bgDiv');
    bgObj.style.position="absolute";
    bgObj.style.top="0";
    bgObj.style.background="#cccccc";
    bgObj.style.filter="progid:DXImageTransform.Microsoft.Alpha(style=3,opacity=25,finishOpacity=75";
    bgObj.style.opacity="0.6";
    bgObj.style.left="0";
    bgObj.style.width=sWidth + "px";
    bgObj.style.height=sHeight + "px";
    bgObj.style.zIndex = "10000";
    document.body.appendChild(bgObj);
    //创建弹出层
    var msgObj=document.createElement("div")
    msgObj.setAttribute("id","msgDiv");
    msgObj.setAttribute("align","center");
    msgObj.style.background="white";
    msgObj.style.border="1px solid " + bordercolor;
    msgObj.style.position = "absolute";
    msgObj.style.left = "50%";
    msgObj.style.top = "50%";
    msgObj.style.font="12px/1.6em Verdana, Geneva, Arial, Helvetica, sans-serif";
    msgObj.style.marginLeft = "-225px" ;
    msgObj.style.marginTop = -75+document.documentElement.scrollTop+"px";
    msgObj.style.width = msgw + "px";
    msgObj.style.height =msgh + "px";
    msgObj.style.textAlign = "center";
    msgObj.style.lineHeight ="25px";
    msgObj.style.zIndex = "10001";    
    var title=document.createElement("h4");
    title.setAttribute("id","msgTitle");
    title.setAttribute("align","right");
    title.style.margin="0";
    title.style.padding="3px";
    title.style.background=bordercolor;
    title.style.filter="progid:DXImageTransform.Microsoft.Alpha(startX=20, startY=20, finishX=100, finishY=100,style=1,opacity=75,finishOpacity=100);";
    title.style.opacity="0.75";
    title.style.border="1px solid " + bordercolor;
    title.style.height="18px";
    title.style.font="12px Verdana, Geneva, Arial, Helvetica, sans-serif";
    title.style.color="white";
    title.style.cursor="pointer";
    title.innerHTML="关闭";
    title.onclick=function(){
    document.body.removeChild(bgObj);
    document.getElementById("msgDiv").removeChild(title);
    document.body.removeChild(msgObj);
    }
    document.body.appendChild(msgObj);
    document.getElementById("msgDiv").appendChild(title);
    var main=document.createElement("div");
    main.setAttribute('id','mainDiv');
    main.style.width = msgw + "px";
    main.style.height =msgh + "px";
    main.setAttribute("align","center");
    main.innerHTML="<div id='div1'></div><div id='div2'></div>";
    document.getElementById("msgDiv").appendChild(main);
    drag("msgDiv",1);
   }
   /**
   *拖动效果
   */
   function drag(o,s)
   {
    if (typeof o == "string") o = document.getElementById(o);
    o.orig_x = parseInt(o.style.left) - document.body.scrollLeft;
    o.orig_y = parseInt(o.style.top) - document.body.scrollTop;
    o.orig_index = o.style.zIndex;
   
    o.onmousedown = function(a)
    {
    this.style.cursor = "move";
    this.style.zIndex = 10000;
    var d=document;
    if(!a)a=window.event;
    var x = a.clientX+d.body.scrollLeft-o.offsetLeft;
    var y = a.clientY+d.body.scrollTop-o.offsetTop;   
    d.ondragstart = "return false;"
    d.onselectstart = "return false;"
    d.onselect = "document.selection.empty();"
   
    if(o.setCapture)
    o.setCapture();
    else if(window.captureEvents)
    window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);


    d.onmousemove = function(a)
    {
    if(!a)a=window.event;
    o.style.left = a.clientX+document.body.scrollLeft-x;
    o.style.top = a.clientY+document.body.scrollTop-y;
    o.orig_x = parseInt(o.style.left) - document.body.scrollLeft;
    o.orig_y = parseInt(o.style.top) - document.body.scrollTop;
    }


    d.onmouseup = function()
    {
    if(o.releaseCapture)
    o.releaseCapture();
    else if(window.captureEvents)
    window.captureEvents(Event.MOUSEMOVE|Event.MOUSEUP);
    d.onmousemove = null;
    d.onmouseup = null;
    d.ondragstart = null;
    d.onselectstart = null;
    d.onselect = null;
    o.style.cursor = "normal";
    o.style.zIndex = o.orig_index;
    }
    }
   
    if (s)
    {
    var orig_scroll = window.onscroll?window.onscroll:function (){};
    window.onscroll = function ()
    {
    orig_scroll();
    o.style.left = o.orig_x + document.body.scrollLeft;
    o.style.top = o.orig_y + document.body.scrollTop;
    }
    }
   }   
 </script>

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics