Js pop-up layer (reLoad function is included in jQuery plug-in form)

Source: Internet
Author: User

When I was working on a project, I felt that the pop-up layer was doing quite well, but there was a problem with the code structure. I used it this time and restructured it into the jQuery plug-in form, and added the reLoad function. The Code is as follows: Copy codeThe Code is as follows: (function ($ ){
$. Module = {
_ ShowCoverLayer: function () {// display the Covering Layer
This. coverLayer = $ ("# TB_overlay ");
Var height = $ (document). height () + "px ";
Var width = $ (document). width () + "px ";
If (this. coverLayer. length> 0 ){
This.coverLayer.css ({"visibility": "visible", "height": height, "width": width });
} Else {
This. coverLayer = $ ("<div id = 'tb _ overlay 'style = 'height:" + height + "; width: "+ width +" '> </div> ");
$ ("Body"). append (this. coverLayer );
}
},
_ HideCoverLayer: function () {// hide the Covering Layer
This.coverLayer.css ("visibility", "hidden ");
},
_ ShowAjaxLoad: function (imgUrl ){
This. ajaxLayer = $ ("# TB_load ");
If (this. ajaxLayer. length> 0 ){
This.ajaxLayer.css ({"visibility": "visible "});
$ ("# TB_loadContent" ).css ({"display": "block "});
} Else {
This. ajaxLayer = $ ("<div id = 'tb _ load'> <div id = 'tb _ loadcontent'> </ div> </div> ");
$ ("Body"). append (this. ajaxLayer );
}
},
_ HideAjaxLoad: function (){
This.ajaxLayer.css ("visibility", "hidden ");
$ ("# TB_loadContent" ).css ({"display": "none "});
},
ShowWin: function (opt) {// url, title, width, height, fixTop, fixLeft, imgUrl, top
This. _ showCoverLayer ();
This. imgUrl = opt. imgUrl | "/image/ajax-loader.gif ";
This. _ showAjaxLoad (this. imgUrl );
This. win = $ ("# TB_window ");
Var that = this;
If (this. win. length = 0 ){
This. win = $ ("<div id = 'tb _ window'> </div> ");
$ ("Body"). append (this. win );
This. win. append ("<div id = 'tb _ closeajaxwindow' style = 'cursor: move 'onmousedown = 'drag (this. parentNode, event); '> <span id = 'tb _ close'> X </span> <span id = 'tb _ title'> "+ opt. title + "</span> </div> <div id = 'tb _ ajaxcontent'> </div> ");
$ ("# TB_close"). click (function (){
That. hideWin ();
});
}

This. _ init (opt );

$ ("# TB_ajaxContent"). load (opt. url, function (){
That. _ hideAjaxLoad ();
That. win. slideDown ("normal ");
});
},
HideWin: function (){
Var that = this;
This. win. fadeOut ("fast", function (){
That. _ hideCoverLayer ();
});
},
_ Init: function (opt ){
$ ("# TB_title" pai.html (opt. title );
Var top = opt. top | ($ (window ). height ()-opt. height)/2 + (opt. fixTop | 0); // + $ (window ). scrollTop ();
Var left = ($ (window ). width ()-opt. width)/2 + (opt. fixLeft | 0); // + $ (window ). scrollLeft ();
This.win.css ({"height": opt. height + "px ",
"Width": opt. width + "px ",
"Top": top + "px ",
"Left": left + "px"
});
},
ReLoad: function (opt) {// load a new page
Var that = this;
This. win. fadeOut ("fast", function (){
That. _ showAjaxLoad (that. imgUrl );
That. _ init (opt );
$ ("# TB_ajaxContent"). load (opt. url, function (){
That. _ hideAjaxLoad ();
That. win. fadeIn ("normal ");
});
});
}
}
}) (JQuery );

The CSS code is as follows:Copy codeThe Code is as follows: body {background-color: # fff ;}
Html, body {height: 100% ;}
Html body {font: 12px Arial, Helvetica, sans-serif; color: #333333}
Html> body {font: 12px Arial, Helvetica, sans-serif; color: #333333}
# TB_overlay {
Position: absolute;
Top: 0;
Left: 0;
Z-index: 100;
Width: 100%;
Height: 100%;
Background-color: # CCC;
Filter: alpha (opacity = 60 );
-Moz-opacity: 0.6;
Opacity: 0.6;
}
# TB_window {
Top: 0px;
Left: 0px;
Position: fixed;
_ Position: absolute;
Background: # fff;
Z-index: 102;
Color: #000000;
Display: none;
Border: 5px solid #666;
}
# TB_caption {
Height: 25px;
Padding: 10px 30px 10px 25px;
}
# TB_closeWindow {
Height: 25px;
Padding: 10px 25px 10px 0;
Float: right;
}
# TB_closeAjaxWindow {
Padding: 5px 10px 7px 0;
Margin-bottom: 1px;
Text-align: right;
Background-color: # e8e8e8;
}
# TB_close {
Cursor: pointer;
}
# TB_title {
Float: left;
Font-weight: bold;
Margin-left: 10px;
}
# TB_ajaxContent {
Padding: 2px 15px 15px 15px;
Overflow: auto;
}
# TB_load {
Text-align: center;
Position: fixed;
Top: 50%;
Left: 0px;
Width: 100%;
Overflow: visible;
Visibility: visible;
Display: block;
Z-index: 101;
}
/* Download by http:// SC .xueit.com */
# TB_loadContent {
Margin-left:-125px;
Position: absolute;
Top:-50px;
Left: 50%;
Width: 250px;
Height: 100px;
Visibility: visible;
}

In this way:Copy codeThe Code is as follows: $. module. showWin ({url: "/deposit/clear/" + depositId + "? "+ (+ New Date ),
Title: "retreat and close ",
Width: 550,
Height: 350 });

The effect is as follows:

When it is disabled, call:Copy codeThe Code is as follows: $. module. hideWin ();

The pop-up layer has several problems:
1. Because $. load () is used, only URLs of the same source can be loaded.
2. In the case of a single page, it can be well located. If it is popped up in iframe, You need to input the top value to help locate it. This problem is caused by the difference between $ (window). top () and iframe values on a single page. I do not know how to solve this problem. I am very grateful to anyone who knows about it.

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.