Here we will introduce you to the use of the jquery pop-up layer and the pop-up layer centered on the page. It will also scroll and center as the page rolls. The following small series will introduce you to you.
Method 1: Customize the pop-up layer
The pop-up layer is commonly used. Here we share a pop-up layer plug-in from someone else, which is used to scroll the page. The pop-up layer is used to center in the middle of the window.
Suppose the HTML code is as follows:
The Code is as follows: |
Copy code |
<! Doctype html> <Html> <Head> <Meta charset = "UTF-8"> <Title> pop-up layer </title> </Head> <Body> <Div class = "btns"> I clicked </div> <Div id = "screen"> </div> <Div class = "popBox"> <Em> disable </em> Here is the content you want to display ...... </Div> </Body> </Html> |
There are two main layers. The screen outside is the page mask layer, which is used to cover the content of the original page.
Css is defined below.
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; } |
Finally, JavaScript is used. This is a plug-in under the jQuery framework. Therefore, 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 (); Detail ('{screen'}.css ({'height': h }); $ ('# Screen'). show (); $ ('. Popbox'). center (); $ ('. Popbox'). fadeIn (); Return false; }); });
// The following is the center 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}, 200, 'linear '); } } </Script> |
Method 2Directly use the JQuery plug-in tips1_wn 1.1, which is simpler than the preceding method.
2. the html of an ID in the pop-up page:
The Code is as follows: |
Copy code |
Tipsdomainwn ("title", "id: testID", "300", "200", "true", "", "true", "id ") |
I am the content in the Test ID
I wrapped a line...
3. Pop-up image:
The Code is as follows: |
Copy code |
Tips0000wn ("image", "img: Image path", "250", "150", "true", "", "true", "img ") |
4.get A. html file (or. php/. asp? Id = 4 ):
The Code is as follows: |
Copy code |
Tipsdomainwn ("title", "url: get? Test.html "," 250 "," 150 "," true "," "," true "," text "); |
5. Load a page to the frame display:
The Code is as follows: |
Copy code |
Tipsreceivwn ("title", "iframe: http://www.bKjia.c0m.net", "900", "580", "true", "", "true", "leotheme "); |
6. A text information layer that cannot be dragged and does not have a masked background is displayed:
The Code is as follows: |
Copy code |
TipsWindown ("prompt", "text: Message content", "250", "150", "false", "", "false", "msg ") |
7. A layer that cannot be dragged and is automatically closed in three seconds is displayed:
The Code is as follows: |
Copy code |
TipsWindown ("prompt", "text: Message content", "250", "150", "false", "3000", "true", "msg ") |