图1(弹出一个div)
图2(弹出多个)
构造函数:
复制代码 代码如下:
var DivWindow= function(popup/*最外层div id*/,popup_drag/*拖动div id*/,popup_exit/*退出按钮id*/ ,exitButton/*触发服务器端退出按钮id*/,varwidth,varheight,zindex){
this.popup =popup ;
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();
};
调用:
复制代码 代码如下:
<input type="button" id="show" onclick="javascript:new DivWindow('popup','popup_drag','popup_exit','exitButton','500','700',4);" value='触发弹出详细基本资料DIV' />
有的地方可能大家觉得有点奇怪,不要问我问什么,因为我有这个需要,有时间再修改一下遮罩效果。更详细代码请见下载
完整代码
.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: 300px; }
div.menu_form_header{
background: url('../images/baseInfo/titleBG.gif') 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 */
/**************************************************
* DivWindow.js
**************************************************/
var DivWindow= function(popup/*最外层div id*/,popup_drag/*拖动div id*/,popup_exit/*退出按钮id*/ ,exitButton/*触发服务器端退出按钮id*/,varwidth,varheight,zindex){
this.popup =popup ; //窗口名称
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);
//_self.obj.style.border = "1px dashed #000000";
//_self.obj.style.filter = "alpha(opacity=30)";
//_self.obj.style.opacity = "0.3";
};
document.onmouseup = function(){
_self.end();
//_self.obj.style.border = "1px solid #cccccc";
//_self.obj.style.borderBottom = "2px solid #E0E0E0";
//_self.obj.style.borderRight = "2px solid #E0E0E0";
//_self.obj.style.filter = "alpha(opacity=100)";
//_self.obj.style.opacity = "1";
};
};
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);
new DivWindow.Drag(obj.childNodes[0] ,obj);
};
//设定窗口优先级
DivWindow.prototype.setTop = function(){
document.getElementById(this.popup).onclick =
document.getElementById(this.popup).onmousedown =
function(){
for(var i=0;i
sffs
片区资料
片区名称:
片区资料2222
片区名称:yj
[Ctrl+A 全选 注:如需引入外部Js需刷新才能执行]
打包下载
您可能感兴趣的文章:
- JS+CSS3制作炫酷的弹窗效果
- js调用父框架函数与弹窗调用父页面函数的简单方法
- JS触摸屏网页版仿app弹窗型滚动列表选择器/日期选择器
- 关于vue.js弹窗组件的知识点总结
- js弹出框、对话框、提示框、弹窗实现方法总结(推荐)
- js弹出div并显示遮罩层
- 如何创建一个JavaScript弹出DIV窗口层的效果
- js点击弹出div层实现可拖曳的弹窗效果
- html 锁定页面(js遮罩层弹出div效果)
- JS+CSS实现Div弹出窗口同时背景变暗的方法
- JS弹窗 JS弹出DIV并使整个页面背景变暗功能的实现代码