JS photo masking implementation code

Source: Internet
Author: User

1. First:

2. Usage:
Initialization: Overlayer. Initialize ({ZIndex: 100, Backgrund: #666, Opacity: 80 });
Display: Overlayer. Show (); or Overlayer. Initialize ({ZIndex: 100, Backgrund: #666, Opacity: 80}). Show ();
Close: Overlayer. Close ();
3. The Code is as follows:
Common functions: Copy codeThe Code is as follows: function getaskentobject ()
{
Var obj;
If (document. compatMode = 'background ')
{
Obj = document. body;
}
Else
{
Obj1_document.doc umentElement
}
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 ));
}
}

Code of the photo masking layer:Copy codeThe Code is as follows :/*
Photo masking Layer
*/
Var Overlayer =
{
// Specifies the ID of the masking layer, which is hard-coded.
ID: '_ DSKJOVERLAYER_BY_KEVIN ',
// Z-axis Sequence
ZIndex: 0,
// Background color
Background: '#333 ',
// Transparency
Opacity: 60,
//
Obj :''
};
/*
Initialization
*/
Overlayer. Initialize = function (o)
{
// Create an Html Element
This. Create ();
// Extended attribute assignment
Extend (this, o );
// Set the 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 elements
*/
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
}
}
/*
Change the window size and reset the width and height.
*/
Overlayer. Resize = function ()
{
If (this. Obj)
{
Var size = GetPageSize ();
This. Obj. style. width = size. width + 'px ';
This. Obj. style. height = size. height + 'px ';
}
}
/*
Display 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
Thank you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.