js點擊彈出div層


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=gb2312" />
<title>點擊后彈出div窗口效果,sky整理收集。 </title>
<style type="text/css">
.mask{position: absolute;
top: 0px;
left: 0px;
filter: alpha(opacity=50);
-moz-opacity:0.5;
opacity:0.5;
background-color: #ffffff;
z-index: 2;
display: none;}
 /*  彈出基本資料div */
div.sample_popup {height:auto; border: 1px solid #327eca; width: 500px;  }
div.menu_form_header{
 background: url('/image/1.jpg') repeat-x;
}
div.sample_popup div.menu_form_header
{
  border-bottom: 0px;
  cursor: default;
   width:100%;
  height:22px;
  line-height: 22px;
  vertical-align: middle;
  text-decoration: none;
  font-family: "Times New Roman", Serif;
  font-weight: 800;
  font-size: 13px;
  color: #206040;
}
div.menu_form_body
{
  width:100%;
  height:150px;
  font-size:12px;
  background-color:#f1f8fe;
}
div.sample_popup input.menu_form_exit
{
  float: right;
  margin: 4px 5px 0px 0px;
  cursor: pointer;
}
/*end:  彈出商品信息div */
    </style>
<script type="text/javascript">
/**************************************************
 * DivWindow.js
 **************************************************/
var DivWindow= function(popup/*最外層div id*/,popup_drag/*拖動div id*/,popup_exit/*退出按鈕id*/ ,exitButton/*觸發服務器端退出按鈕id*/,varwidth,varheight,zindex){
 this.popup =popup ; //窗口名稱
  this.popup_drag=popup_drag;
 this.height =varheight ; //窗口高度,並沒用來設置窗口高度寬度,用來定位在屏幕的位置
 this.width =varwidth ; //窗口寬度
        this.popup_exit=popup_exit;
        this.exitButton=exitButton;
        this.zindex=zindex;
 this.init = function(){ //初始化窗口
  this.popupShow();
  this.startDrag(); //設置拖動
  this.setCommond(); //設置關閉
  DivWindow.ArrayW.push(document.getElementById(this.popup)); //存儲窗口到數組
 };this.init();
};
//存儲窗口到數組
DivWindow.ArrayW = new Array();
//字符串連接類
DivWindow.StringBuild = function(){
 this.arr = new Array();
 this.push = function(str){
  this.arr.push(str);
 };
 this.toString = function(){
  return this.arr.join("");
 };
};
//拖動類
DivWindow.Drag = function(o ,oRoot){
 var _self = this;
 //拖動對象
 this.obj = (typeof oRoot != "undefined") ?oRoot : o;
 this.relLeft = 0; //記錄橫坐標
 this.relTop = 0; //記錄縱坐標
 o.onselectstart = function(){
  return false;
 };
 o.onmousedown = function(e){ //鼠標按下
  e = _self.fixE(e);
  _self.relLeft = e.clientX - _self.fixU(_self.obj.style.left);
  _self.relTop = e.clientY - _self.fixU(_self.obj.style.top);
  document.onmousemove = function(e){
   _self.drag(e);

  };
  document.onmouseup  = function(){
   _self.end();

  };
 };
 this.drag = function(e){ //拖動
  e = this.fixE(e);
  var l = e.clientX - this.relLeft;
  var t = e.clientY - this.relTop;
  if (t < 0)
  {
   t = 0; //防止頭部消失
  }
  this.obj.style.left = l +"px";
  this.obj.style.top = t +"px";
 };
 this.end = function(){ //結束拖動
  document.onmousemove = null;
  document.onmouseup = null;
 };
 this.fixE = function(e){ //修復事件
  if (typeof e == "undefined") e = window.event;
  return e;
 };
 this.fixU = function(u){ //處理px單位
  return parseInt(u.split("p")[0]);
 };
};
//窗口拖動
DivWindow.prototype.startDrag = function(){
 var obj = document.getElementById(this.popup);
        var drag = document.getElementById(this.popup_drag);
 new DivWindow.Drag(drag,obj);
};
//設定窗口優先級
DivWindow.prototype.setTop = function(){
 document.getElementById(this.popup).onclick =
 document.getElementById(this.popup).onmousedown =
 function(){
  for(var i=0;i<DivWindow.ArrayW.length;i++)
  {
   DivWindow.ArrayW[i].style.zIndex = 1;
  }
  this.style.zIndex = 100;
 };
};
//顯示
DivWindow.prototype.popupShow=function()
{       document.getElementById('mask').style.display="block";
        document.getElementById('mask').style.width=window.screen.width +20;
        document.getElementById('mask').style.height=window.screen.width +20;
        var  element      = document.getElementById(this.popup);
        element.style.position   = "absolute";
        element.style.visibility = "visible";
        element.style.display    = "block";
        element.style.width=this.width;
        element.style.height='auto';
        element.style.left = (window.screen.width - this.width)/2+"px";
        //element.style.top  =(window.screen.height-this.height-100)/2+"px";
         element.style.top  =20+"px";
        element.style.zIndex=this.zindex;
}
//設置關閉
DivWindow.prototype.setCommond = function(){
 var _self = this;
 //根對象
 var obj = document.getElementById(this.popup);
 var exit = document.getElementById(this.popup_exit);
 var triggServerEvent=document.getElementById(this.exitButton);
//歡迎來到站長特效網,我們的網址是www.zzjs.net,很好記,zz站長,js就是js特效,本站收集大量高質量js代碼,還有許多廣告代碼下載。
 //設置關閉
      exit.onclick = function(){
      obj.style.display = "none";
      obj.style.visibility = 'hidden';
                    document.all.mask.style.display='none'//關閉遮罩層
                    triggServerEvent.click();//觸發服務器端退出事件
     };
};
</script>
</head>
<body>

<div>
 <input type="button"  id="show" onclick="javascript:new DivWindow('popup','popup_drag','popup_exit','exitButton','500','700',4);"  value='點擊彈出窗口'   />

</div>
  <!-- 遮罩層 -->
 <div id="mask"  class="mask">
 </div>
<!-- 彈出基本資料詳細DIV層 -->
<div class="sample_popup" id="popup" style="visibility: hidden; display: none;">
<div class="menu_form_header" id="popup_drag">
 <input type="button"  id="popup_exit" value="退出"/>
</div>
<div class="menu_form_body" >
 <div id="popDetail">
 

 <script >
function unselectall(){
if(document.myform.chkAll.checked){
document.myform.chkAll.checked = document.myform.chkAll.checked&0;
}
}
function CheckAll(form){
for (var i=0;i<form.elements.length;i++){
var e = form.elements[i];
if (e.Name != 'chkAll'&&e.disabled==false)
e.checked = form.chkAll.checked;
}
}
</script>


<form name="myform" method="post" id="myform" action="" >

<input name='id' type='checkbox' onclick='unselectall()' id='id' value='1'> 設計家園

<input name='id' type='checkbox' onclick='unselectall()' id='id' value='2'> 網頁教程

<input name='id' type='checkbox' onclick='unselectall()' id='id' value='3'> 酷站欣賞

<input name='id' type='checkbox' onclick='unselectall()' id='id' value='4'> 網頁素材

<input name='chkAll' type='checkbox' id='chkAll' onclick='CheckAll(this.form)' value='checkbox'>
全選

</form>

</div>
</div>
</div>
</body>
</html>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM