jquery pop-up window centered, scrolling with page scrolling

Source: Internet
Author: User
Tags jquery library

Method One, custom pop-up layer

Pop-up layer, we commonly used, here to share a person's pop-up layer plugin, page scrolling, pop-up layer used to center in the middle of the window position.
If the HTML code is as follows

  code is as follows copy code
  <! DOCTYPE html>
            < Meta charset= "Utf-8"
    <title> pop-up layer </title>
        <body>
    <div class= "btns" > I dot </div>
     <div id= "screen" ></div>
    <div class= "PopBox"
    <em> close </em>
    Here's what you want to show, skip ...
    </div>
    </body>
    /tr>

Mainly a total of 2 layers, the outside screen is a page mask layer, used to cover the contents of the original page, can not be used.
Here's a definition of CSS.

The code is as follows Copy Code
*{
margin:0;
padding:0;
}

#screen {
width:100%;
height:100%;
Position:absolute;
top:0;
left:0;
Display:none;
z-index:9998;
Background: #666;
opacity:0.5;
Filter:alpha (OPACITY=50);
-moz-opacity:0.5;
}

. popbox{
width:600px;
Background: #fff;
border:2px #8FA4F5 Solid;
padding:1px;
Position:absolute;
top:0;
left:0;
Display:none;
z-index:9999;
}

. PopBox em{
PADDING:2PX 5px;
Position:absolute;
right:10px;
top:10px;
Background: #333;
Color: #fff;
}

The last is JS, which is a plugin in the jquery framework, so remember to introduce the jquery library file.

The code is as follows Copy Code
<script type= "Text/javascript" >
Use.
$ (function () {
$ ('. PopBox em '). Click (function () {
$ ('. PopBox '). fadeout (function () {$ (' #screen '). Hide ();});
return false;
});
$ ('. Btns '). Click (function () {
var h = $ (document). Height ();
$ (' #screen '). css ({' Height ': h});
$ (' #screen '). Show ();
$ ('. PopBox '). Center ();
$ ('. PopBox '). FadeIn ();
return false;
});
});

The following is a centered plug-in.
JQuery.fn.center = function (loaded) {
var obj = this;
Body_width = parseint ($ (window). width ());
Body_height = parseint ($ (window). Height ());
Block_width = parseint (Obj.width ());
Block_height = parseint (Obj.height ());
Left_position = parseint (BODY_WIDTH/2)-(BLOCK_WIDTH/2) + $ (window). scrollleft ());
if (body_width<block_width) {left_position = 0 + $ (window). scrollleft ();
Top_position = parseint (BODY_HEIGHT/2)-(BLOCK_HEIGHT/2) + $ (window). scrolltop ());
if (body_height<block_height) {top_position = 0 + $ (window). scrolltop ();
if (!loaded) {
Obj.css ({' position ': ' absolute '});
Obj.css ({' Top ': top_position, ' Left ': left_position});
$ (window). Bind (' Resize ', function () {
Obj.center (!loaded);
});
$ (window). bind (' scroll ', function () {
Obj.center (!loaded);
});
} else {
Obj.stop ();
Obj.css ({' position ': ' absolute '});
Obj.animate ({' Top ': top_position}, ' linear ');
}
}
</script>


method Two , directly with the jquery plug-in Tipswindown 1.1, simpler than the above method

2. HTML for an ID in the pop-up page:

The code is as follows Copy Code
Tipswindown ("title", "Id:testid", "+", "+", "true", "", "true", "id")

I'm the content in the test ID.

I changed the line ...
3. Pop-up pictures:

The code is as follows Copy Code
Tipswindown ("Pictures", "img: Picture Paths", "the", "" "," true "," "," true "," IMG ")

4.get load an. html file (or it can be. php/.asp?id=4):

The code is as follows Copy Code
Tipswindown ("title", "Url:get?test.html", "the" "," "," "true", "", "true", "text");

5. Load a page to the frame display:

The code is as follows Copy Code

Tipswindown ("title", "Iframe:http://www.111cn.net.net", "900", "580", "true", "", "true", "Leotheme");

6. POPs up a text information layer that cannot be dragged and has no mask background:

The code is as follows Copy Code
Tipswindown ("Hint", "text: Hint information content", "a", "" "," false "," "," false "," MSG ")

7. Eject a layer that cannot be dragged and automatically closed for three seconds:

  code is as follows copy code

Tipswindown ("Hint", "text: Hint information content", "3000", "I", "false", "true", "MSG")

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.