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操作XML實(shí)例總結(jié)(加載與解析XML文件、字符串)
這篇文章主要介紹了JS操作XML的方法,結(jié)合實(shí)例形式總結(jié)分析了JavaScript加載與解析XML文件及字符串的相關(guān)技巧,需要的朋友可以參考下2015-12-12ant-design-pro?的EditableProTable表格驗(yàn)證調(diào)用的實(shí)現(xiàn)代碼
這篇文章主要介紹了ant-design-pro?的EditableProTable表格驗(yàn)證調(diào)用,這里的需求是點(diǎn)擊外部的保存要對(duì)整個(gè)表單進(jìn)行驗(yàn)證,本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-06-06提交按鈕的name=''submit''引起的js失效問(wèn)題及原因
這篇文章主要介紹了提交按鈕的name='submit'引起的js失效問(wèn)題及原因,需要的朋友可以參考下2015-02-02小程序云開(kāi)發(fā)獲取不到數(shù)據(jù)庫(kù)記錄的解決方法
這篇文章主要為大家詳細(xì)介紹了小程序云開(kāi)發(fā)獲取不到數(shù)據(jù)庫(kù)記錄的解決方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-05-05js和jquery批量綁定事件傳參數(shù)一(新豬豬原創(chuàng))
js綁定事件傳參,javascript綁定事件傳參數(shù),jquery綁定事件傳參數(shù)2010-06-06JavaScript Event Loop相關(guān)原理解析
這篇文章主要介紹了JavaScript Event Loop相關(guān)原理解析,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-06-06鼠標(biāo)懸停小圖標(biāo)顯示大圖標(biāo)
這篇文章主要介紹了鼠標(biāo)懸停小圖標(biāo)顯示大圖標(biāo)的相關(guān)資料,需要的朋友可以參考下2016-01-01