一个锁定层
/**
* 创建一个遮盖层
* id:遮盖层的id,如果为null,则自动生成一个id
* cssObj:遮盖层的样式对象,也可以是一个类名
* opacity:一个0-1之间的小数,表示透明度,数字越小透明度越高
*/
function Lock(id,cssObj,opacity) {
Lock.num=Lock.num||1;
Lock.num++;
//当前遮盖层的id
var lockID = id ||'divlock_'+Lock.num;
//默认样式
cssObj=cssObj||{backgroundColor:"black",filter:"alpha(Opacity=40)",opacity:"0.4",zIndex:"1"};
if(opacity)
{
cssObj.opacity=opacity;
cssObj.filter="alpha(Opacity="+(opacity*100)+")";
}
//一个getElementById的简写函数
var $=function(id){document.getElementById(id);};
//如果已经有同名的Dom元素,则返回此函数
if($(id))
{
this.success=false;
this.errorMsg='id重复';
return;
}
var divLock = document.createElement("div");
//获取当前页面的高度
var getBodyHeight= function ()
{
//如果是IE
if(document.all)
{
return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight,document.documentElement.clientHeight);
}
return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
};
divLock.id=lockID;
divLock.style.width = Math.max(document.body.scrollWidth,document.documentElement.scrollWidth)+"px"
divLock.style.height = getBodyHeight()+"px";
divLock.style.position = "absolute";
divLock.style.top = "0px";
divLock.style.left = "0px";
divLock.style.display="none";
//divLock.style.verticalAlign="middle";
setClass(divLock,cssObj);
document.body.appendChild(divLock);
this.div=divLock;
this.removed=false;
this.show=function(){
if(this.removed)
{
return;
}
this.div.style.display="block";
};
this.hidden=function(){
if(this.removed)
{
return;
}
this.div.style.display="none";
};
this.remove=function(){
this.div.parentNode.removeChild(this.div);
this.removed=true;
}
}
* 创建一个遮盖层
* id:遮盖层的id,如果为null,则自动生成一个id
* cssObj:遮盖层的样式对象,也可以是一个类名
* opacity:一个0-1之间的小数,表示透明度,数字越小透明度越高
*/
function Lock(id,cssObj,opacity) {
Lock.num=Lock.num||1;
Lock.num++;
//当前遮盖层的id
var lockID = id ||'divlock_'+Lock.num;
//默认样式
cssObj=cssObj||{backgroundColor:"black",filter:"alpha(Opacity=40)",opacity:"0.4",zIndex:"1"};
if(opacity)
{
cssObj.opacity=opacity;
cssObj.filter="alpha(Opacity="+(opacity*100)+")";
}
//一个getElementById的简写函数
var $=function(id){document.getElementById(id);};
//如果已经有同名的Dom元素,则返回此函数
if($(id))
{
this.success=false;
this.errorMsg='id重复';
return;
}
var divLock = document.createElement("div");
//获取当前页面的高度
var getBodyHeight= function ()
{
//如果是IE
if(document.all)
{
return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight,document.documentElement.clientHeight);
}
return Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
};
divLock.id=lockID;
divLock.style.width = Math.max(document.body.scrollWidth,document.documentElement.scrollWidth)+"px"
divLock.style.height = getBodyHeight()+"px";
divLock.style.position = "absolute";
divLock.style.top = "0px";
divLock.style.left = "0px";
divLock.style.display="none";
//divLock.style.verticalAlign="middle";
setClass(divLock,cssObj);
document.body.appendChild(divLock);
this.div=divLock;
this.removed=false;
this.show=function(){
if(this.removed)
{
return;
}
this.div.style.display="block";
};
this.hidden=function(){
if(this.removed)
{
return;
}
this.div.style.display="none";
};
this.remove=function(){
this.div.parentNode.removeChild(this.div);
this.removed=true;
}
}