首页 >web前端 >html教程 >Div+Css+JS做弹出窗口_html/css_WEB-ITnose

Div+Css+JS做弹出窗口_html/css_WEB-ITnose

WBOY
WBOY原创
2016-06-24 12:32:081417浏览

   很久就想做下笔记,把这段时间学到用到的东西都记录下来,以备以后可能重复利用,好啦,开始...

  Div+Css+JS 这三者都是互相影响的,缺一不可。

  首先写好CSS样式,

CSS
#divbg
        {
            width: 100%;
            height: 100%;
            position: absolute;
            z-index: 999;
            top: 0px;
            left: 0px;
            filter: alpha(opacity=50);
            opacity: 0.5;
            background-color: #AAAAAA;
        }
        #diveditcontent
        {
            width: 630px;
            height: 150px;
            position: absolute;
            z-index: 1000;
            background-color: #444444;
        }
        #divheader
        {
            width: 100%;
            height: 25px;
            background-color: #BB5500;
        }

 

  直接贴上代码了。

Html


     //弹出窗口的背景(遮挡当前页)
        //窗口内容页
        

            
">    //窗口标题行
                

                    
                        Edit

                

                    X
  //关闭
            

            
  //内容
            

        

    

 

 

JavaScript
<script> <br /> var divheader = document.getElementById("divheader"); <br /> var divbg = document.getElementById("divbg"); <br /> var diveditcontent = document.getElementById("diveditcontent"); <br /> var selects = document.getElementsByTagName("select"); <br /> var divcontent = document.getElementById("divcontent"); <br /> function Show(Key) { <br /> <br /> divbg.style.display = ""; <br /> divbg.style.width = document.body.offsetWidth; //浏览器宽度(滚动条+clientwidth+边框) <br /> divbg.style.height = document.body.offsetHeight; <br /> <br /> diveditcontent.style.display = ""; <br /> diveditcontent.style.top = "50px"; //弹出窗口位置 <br /> diveditcontent.style.left = "100px"; <br /> <br /> <br /> for (var i = 0; i < selects.length; i++) { <br /> selects[i].style.display = "none"; //遮住下拉框 <br /> } <br /> <br /> divcontent.innerHTML = "<iframe frameborder=0 scrolling=no src='PriceEdit.aspx?Key=" + Key + "' width='100%' height='100%'>"; <br /> //嵌入页 <br /> <br /> } <br /> function Hide() { <br /> //隐藏窗口 <br /> document.location = location.reload(); <br /> divbg.style.display = "none"; <br /> diveditcontent.style.display = "none"; <br /> <br /> for (var i = 0; i < selects.length; i++) { <br /> selects[i].style.display = ""; <br /> } <br /> <br /> <br /> } <br /> divheader.onmousedown = Down; <br /> //以下是拉窗口自由移动 <br /> var th; <br /> var tw; <br /> function Down(e) { <br /> <br /> var event = window.event || e; <br /> th = event.clientY - parseInt(diveditcontent.style.top.replace(/px/, ""), 10); <br /> tw = event.clientX - parseInt(diveditcontent.style.left.replace(/px/, ""), 10); <br /> document.onmousemove = Move; <br /> document.onmouseup = Up; <br /> document.onmouseout = Up; <br /> function Move(e) { <br /> <br /> var event = window.event || e; <br /> var top = event.clientY - th; <br /> var left = event.clientX - tw; <br /> top = top < 0 ? 0 : top; <br /> top = top > document.body.offsetHeight - 220 ? document.body.offsetHeight - 220 : top; <br /> <br /> left = left < 0 ? 0 : left; <br /> left = left > document.body.offsetWidth - 630 ? document.body.offsetWidth - 630 : left; <br /> <br /> diveditcontent.style.top = top + "px"; <br /> diveditcontent.style.left = left + "px"; <br /> } <br /> <br /> function Up() { <br /> document.onmousemove = null; <br /> } <br /> } <br /> </script>

 

 结束。继续上班

 

 

 

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn