JS 遮照層實(shí)現(xiàn)代碼
更新時(shí)間:2010年03月31日 23:58:28 作者:
JS 遮照層實(shí)現(xiàn)代碼,需要的朋友可以參考下。
1.先上效果圖:

2.使用方法:
初始化:Overlayer.Initialize({ZIndex:100,Backgrund:#666,Opacity:80});
顯示:Overlayer.Show();或Overlayer.Initialize({ZIndex:100,Backgrund:#666,Opacity:80}).Show();
關(guān)閉:Overlayer.Close();
3.代碼如下:
公用函數(shù):
function GetDocumentObject()
{
var obj;
if(document.compatMode=='BackCompat')
{
obj=document.body;
}
else
{
obj=document.documentElement
}
return obj;
}
function GetPageSize()
{
var obj = GetDocumentObject();
//alert('pagesize:'+obj);
with(obj)
{
return {width:((scrollWidth>clientWidth)?scrollWidth:clientWidth),height:( (scrollHeight>clientHeight)?scrollHeight:clientHeight)}
}
}
var Extend = function(destination, source)
{
for (var property in source)
{
destination[property] = source[property];
}
};
var BindAsEventListener = function(object, fun)
{
var args = Array.prototype.slice.call(arguments).slice(2);
return function(event)
{
return fun.apply(object, [event || window.event].concat(args));
}
}
遮照層代碼:
/*
遮照層
*/
var Overlayer=
{
//遮照層ID,這個(gè)是硬編碼的
ID:'__DSKJOVERLAYER_BY_KEVIN',
//Z軸順序
ZIndex:0,
//背景顏色
Background:'#333',
//透明度
Opacity:60,
//
Obj:''
};
/*
初始化
*/
Overlayer.Initialize=function(o)
{
//創(chuàng)建Html元素
this.Create();
//擴(kuò)展屬性賦值
Extend(this,o);
//設(shè)置樣式
this.SetStyleCss();
//附加事件
AddListener(window,'resize',BindAsEventListener(this,this.Resize));
AddListener(window,'scroll',BindAsEventListener(this,function()
{
this._PageSize=GetPageSize();
if(this._PageSize.height!=this._height)
{
this.Resize();
this._height=this._PageSize.height;
}
}));
return this;
}
/*
創(chuàng)建HTML元素
*/
Overlayer.Create=function()
{
//alert('create');
var obj=$(this.ID);
if(!obj)
{
obj = document.createElement('div');
obj.id=this.ID;
obj.style.display='none';
document.body.appendChild(obj);
}
this.Obj=obj;
}
/*
設(shè)置樣式
*/
Overlayer.SetStyleCss=function()
{
with(this.Obj.style)
{
position = 'absolute';
background = this.Background;
left = '0px';
top = '0px';
this.Resize();
zIndex = this.ZIndex;
filter = 'Alpha(Opacity='+this.Opacity+')';//IE逆境
opacity = this.Opacity/100;//非IE
}
}
/*
窗口改變大小時(shí)重新設(shè)置寬度和高度
*/
Overlayer.Resize=function()
{
if(this.Obj)
{
var size=GetPageSize();
this.Obj.style.width=size.width+'px';
this.Obj.style.height=size.height+'px';
}
}
/*
顯示層
*/
Overlayer.Show=function()
{
//alert('show'+Overlayer.ID);
if(this.Obj)
{
this.Obj.style.display='block';
this.Resize();
}
}
/*
關(guān)閉層,采用隱藏層的方法實(shí)現(xiàn)
*/
Overlayer.Close=function()
{
var overlay=this.Obj;
if(overlay)
{
overlay.style.display='none';
}
}
4.結(jié)束語(yǔ)
歡迎拍磚,謝謝。
2.使用方法:
初始化:Overlayer.Initialize({ZIndex:100,Backgrund:#666,Opacity:80});
顯示:Overlayer.Show();或Overlayer.Initialize({ZIndex:100,Backgrund:#666,Opacity:80}).Show();
關(guān)閉:Overlayer.Close();
3.代碼如下:
公用函數(shù):
復(fù)制代碼 代碼如下:
function GetDocumentObject()
{
var obj;
if(document.compatMode=='BackCompat')
{
obj=document.body;
}
else
{
obj=document.documentElement
}
return obj;
}
function GetPageSize()
{
var obj = GetDocumentObject();
//alert('pagesize:'+obj);
with(obj)
{
return {width:((scrollWidth>clientWidth)?scrollWidth:clientWidth),height:( (scrollHeight>clientHeight)?scrollHeight:clientHeight)}
}
}
var Extend = function(destination, source)
{
for (var property in source)
{
destination[property] = source[property];
}
};
var BindAsEventListener = function(object, fun)
{
var args = Array.prototype.slice.call(arguments).slice(2);
return function(event)
{
return fun.apply(object, [event || window.event].concat(args));
}
}
遮照層代碼:
復(fù)制代碼 代碼如下:
/*
遮照層
*/
var Overlayer=
{
//遮照層ID,這個(gè)是硬編碼的
ID:'__DSKJOVERLAYER_BY_KEVIN',
//Z軸順序
ZIndex:0,
//背景顏色
Background:'#333',
//透明度
Opacity:60,
//
Obj:''
};
/*
初始化
*/
Overlayer.Initialize=function(o)
{
//創(chuàng)建Html元素
this.Create();
//擴(kuò)展屬性賦值
Extend(this,o);
//設(shè)置樣式
this.SetStyleCss();
//附加事件
AddListener(window,'resize',BindAsEventListener(this,this.Resize));
AddListener(window,'scroll',BindAsEventListener(this,function()
{
this._PageSize=GetPageSize();
if(this._PageSize.height!=this._height)
{
this.Resize();
this._height=this._PageSize.height;
}
}));
return this;
}
/*
創(chuàng)建HTML元素
*/
Overlayer.Create=function()
{
//alert('create');
var obj=$(this.ID);
if(!obj)
{
obj = document.createElement('div');
obj.id=this.ID;
obj.style.display='none';
document.body.appendChild(obj);
}
this.Obj=obj;
}
/*
設(shè)置樣式
*/
Overlayer.SetStyleCss=function()
{
with(this.Obj.style)
{
position = 'absolute';
background = this.Background;
left = '0px';
top = '0px';
this.Resize();
zIndex = this.ZIndex;
filter = 'Alpha(Opacity='+this.Opacity+')';//IE逆境
opacity = this.Opacity/100;//非IE
}
}
/*
窗口改變大小時(shí)重新設(shè)置寬度和高度
*/
Overlayer.Resize=function()
{
if(this.Obj)
{
var size=GetPageSize();
this.Obj.style.width=size.width+'px';
this.Obj.style.height=size.height+'px';
}
}
/*
顯示層
*/
Overlayer.Show=function()
{
//alert('show'+Overlayer.ID);
if(this.Obj)
{
this.Obj.style.display='block';
this.Resize();
}
}
/*
關(guān)閉層,采用隱藏層的方法實(shí)現(xiàn)
*/
Overlayer.Close=function()
{
var overlay=this.Obj;
if(overlay)
{
overlay.style.display='none';
}
}
4.結(jié)束語(yǔ)
歡迎拍磚,謝謝。
相關(guān)文章
js圖片實(shí)時(shí)加載提供網(wǎng)頁(yè)打開速度
沒必要一開始加載就要把全部圖片加載出來,這樣子打開網(wǎng)面的速度得到了很好提高,下面有個(gè)不錯(cuò)的思路,大家可以看看2014-09-09
javascript一些不錯(cuò)的函數(shù)腳本代碼
收集一些不多見的好用的自定義函數(shù)代碼 計(jì)算字符長(zhǎng)度的js函數(shù) 去字符中前后的空格的js函數(shù) 圖片自適應(yīng)大小函數(shù)代碼2008-09-09
詳解JavaScript中的鏈?zhǔn)秸{(diào)用
這篇文章主要介紹了JavaScript中的鏈?zhǔn)秸{(diào)用的相關(guān)資料,幫助大家更好的理解和學(xué)習(xí)JavaScript,感興趣的朋友可以了解下2020-11-11
canvas實(shí)現(xiàn)手機(jī)端用來上傳用戶頭像的代碼
這篇文章主要介紹了canvas實(shí)現(xiàn)手機(jī)端用來上傳用戶頭像的代碼代碼簡(jiǎn)單易懂非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下2016-10-10
JavaScript表單驗(yàn)證實(shí)例之驗(yàn)證表單項(xiàng)是否為空
表單驗(yàn)證幾乎在每個(gè)需要注冊(cè)或者是登錄的網(wǎng)站都是必不可少,下面通過本篇文章給大家介紹JavaScript表單驗(yàn)證實(shí)例之驗(yàn)證表單項(xiàng)是否為空,涉及到j(luò)s表單驗(yàn)證實(shí)例相關(guān)知識(shí),對(duì)js表單驗(yàn)證實(shí)例代碼需要的朋友一起學(xué)習(xí)吧2016-01-01

