Js pops up the div and displays the Mask Layer

Source: Internet
Author: User

Js pops up the div and displays the Mask Layer

The div is displayed to show the effect of the mask layer. You must have seen it. The following is an example. For more information, see.

The Code is as follows:

// -------------------- Pop-up layer -------------------

// PopDivId: the ID of the pop-up layer div

// DragDivId: ID used to drag a div

// IsShowMask: whether to display the Mask Layer

Function popDivShow (popDivId, dragDivId, isShowMask ){

If (isShowMask ){

CreatMask (popDivId );

}

Var oWins = document. getElementById (popDivId );

Var oWins_title = document. getElementById (dragDivId );

Var bDrag = false;

Var disX = disY = 0;

OWins. style. display = "block ";

OWins_title.onmousedown = function (event ){

Var event = event | window. event;

BDrag = true;

DisX = event. clientX-oWins. offsetLeft;

DisY = event. clientY-oWins. offsetTop;

This. setCapture & this. setCapture ();

Return false;

};

Document. onmousemove = function (event ){

If (! BDrag)

Return;

Var event = event | window. event;

Var iL = event. clientX-disX;

Var iT = event. clientY-disY;

Var maxL = document.doc umentElement. clientWidth-oWins. offsetWidth;

Var maxT = document.doc umentElement. clientHeight-oWins. offsetHeight;

IL = iL <0? 0: iL;

IL = iL> maxL? MaxL: iL;

IT = iT <0? 0: iT;

IT = iT> maxT? MaxT: iT;

OWins. style. marginTop = oWins. style. marginLeft = 0;

OWins. style. left = iL + "px ";

OWins. style. top = iT + "px ";

Return false;

};

Document. onmouseup = window. onblur = oWins_title.onlosecapture = function (){

BDrag = false;

OWins_title.releaseCapture & oWins_title.releaseCapture ();

};

}

// Hide the pop-up layer

Function popDivHidden (popDivId ){

Var oWins = document. getElementById (popDivId );

OWins. style. display = "none ";

Registry.parent.document.body.removechild(registry.parent.doc ument. getElementById ("maskDiv "));

}

// Obtain the zIndex of the pop-up layer

Function getZindex (popDivId ){

Var popDiv = document. getElementById (popDivId );

Var popDivZindex = popDiv. style. zIndex;

Return popDivZindex;

 

}

// Create a Mask Layer

Function creatMask (popDivId ){

// Parameter w is the width of the pop-up page, parameter h is the height of the pop-up page, and parameter s is the path of the pop-up page

Var maskDiv = callback parent.doc ument. createElement ("div ");

MaskDiv. id = "maskDiv ";

MaskDiv. style. position = "fixed ";

MaskDiv. style. top = "0 ";

MaskDiv. style. left = "0 ";

MaskDiv. style. zIndex = getZindex (popDivId)-1;

MaskDiv. style. backgroundColor = "#333 ";

MaskDiv. style. filter = "alpha (opacity = 70 )";

MaskDiv. style. opacity = "0.7 ";

MaskDiv. style. width = "100% ";

MaskDiv. style. height = (partition partition parent.doc ument. body. scrollHeight + 50) + "px ";

Extends extends parent.doc ument. body. appendChild (maskDiv );

MaskDiv. onmousedown = function (){

Registry.parent.document.body.removechild(registry.parent.doc ument. getElementById ("maskDiv "));

};

}

 

Related Article

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.