2.使用方法:
初始化:Overlayer.Initialize({ZIndex:100/Backgrund:#666">
Home > Web Front-end > JS Tutorial > body text

JS shading layer implementation code_javascript skills

WBOY
Release: 2016-05-16 18:30:55
Original
929 people have browsed it

1. First, the rendering:

2. How to use:
Initialization: Overlayer.Initialize({ZIndex:100,Backgrund:#666,Opacity:80} );
Show: Overlayer.Show(); or Overlayer.Initialize({ZIndex:100,Backgrund:#666,Opacity:80}).Show();
Close: Overlayer.Close();
3. The code is as follows:
Public function:

Copy code The code is as follows:

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));
}
}

Occlusion layer code:
Copy code The code is as follows:

/*
Overlay layer
*/
var Overlayer=
{
//Overlay layer ID, this is hard-coded
ID:'__DSKJOVERLAYER_BY_KEVIN',
//Z-axis order
ZIndex:0,
//Background color
Background:'#333',
//Transparency
Opacity:60,
//
Obj:''
};
/*
Initialization
*/
Overlayer.Initialize=function(o)
{
//Create Html element
this .Create();
//Extended attribute assignment
Extend(this,o);
//Set style
this.SetStyleCss();
//Additional event
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;
}
/*
Create HTML element
*/
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;
}
/*
Set Style
*/
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 adversity
opacity = this.Opacity/100;//Non-IE
}
}
/*
Window change Resize width and height when resizing
*/
Overlayer.Resize=function()
{
if(this.Obj)
{
var size=GetPageSize();
this.Obj.style.width=size.width 'px';
this.Obj.style.height=size.height 'px';
}
}
/*
Show layer
*/
Overlayer.Show=function()
{
//alert('show' Overlayer.ID);
if(this.Obj)
{
this.Obj.style.display='block';
this.Resize();
}
}
/*
Close the layer and use the hidden layer method
*/
Overlayer.Close=function()
{
var overlay=this.Obj;
if(overlay)
{
overlay.style.display='none ';
}
}

4. Conclusion
Welcome to make bricks, thank you.
Related labels:
js
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template