As far as jquery is concerned, there are a lot of good players to develop the pop-up layer plug-ins, even the jquery official also provides Dialog UI components.
I have written some of the effects of the pop-up layer before, but also by the help of others to develop a good jQuery plug-ins, the advantages of these plug-ins are many parameters, full-featured, easy to call, but will inevitably lead to the plug-in script is too large, a lot of basic functions are not used, thanks to the life of children's shoes awakened dream of people, in fact, pop-up dialog layer with JQuery to achieve is quite simple, simple to only need two words JS, one is pop-up, the other is closed. Eliminates a lot of unnecessary redundancy of functionality and JS code.
Take a look at the DEMO first, and then look at how simple the code is:
The code is as follows |
Copy Code |
<! DOCTYPE html> <meta charset= "UTF-8"/> <style type= "Text/css" > #layer { width:600px; height:300px; Background: #ccc; border:1px solid #aaa; position:fixed; _position:absolute; * * Barely cope with IE6 * * top:50%; right:50%; margin:-150px-300px 0 0; Display:none; /* default does not show * * } #close { Position:absolute; top:0; right:0; FONT:20PX/1 Arial; Text-decoration:none; } </style> <script type= "Text/javascript" src= "Js/jquery.js" ></script> <title>jquery Lite Popup Dialog Layer </title> <body> <input type= "Submit" id= "layerbtn" value= "dot I dot I'll hurry I!!! "/> <div id= "Layer" > <p> I play it out? (? 3?)? </p> <p> I play it out? ( ̄? ̄)?</p> <p> I play out ~ ("?-?) /</p> <p> I play it out? (?</p>) <p> I play it out ~ O (∩_∩) o </p> <p> I play it out? (???)? </p> <p> I play it out ~ (???) /~</p> <p> I play it out ~ Y (^_^) y</p> <a href= "javascript:void (0)" title= "Off" id= "Close" >X</a> </div> <script type= "Text/javascript" > $ (document). Ready (function () { $ (' #layerBtn '). Click (function () {$ (' #layer '). FadeIn (); $ (' #close '). Click (function () {$ (' #layer '). fadeout (); }); </script> <br/><br/><br/><br/><br/><br/><br/><br/><br/>< br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>< br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>< br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>< br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>< br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>< br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>< br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>< br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/& gt;<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/& gt;<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/& gt;<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/& gt;<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/& gt;<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/& gt;<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/& gt;<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/& gt;<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>& lt;br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>& lt;br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>& lt;br/><br/><br/><br/> </body> |
Because we generally require the pop-up layer relative to the browser window vertically horizontally, and can follow the scroll bar down and move down, so I used the position:fixed; But IE6 always compare cups, but do not support such a CSS, but I used the position:absolute; To deal with IE6, but this can only solve the bug, because the Position:absolute can only be fixed in the first screen of the vertical center, and can not move down with the scroll bar, specifically how to solve the fixed this IE6 bug here is not much waste of breath.
3, JS part, of course, must first load jQuery:
The code is as follows |
Copy Code |
$ (document). Ready (function () { $ (' #layerBtn '). Click (function () {$ (' #layer '). FadeIn (); Pop-up layer $ (' #close '). Click (function () {$ (' #layer '). fadeout (); Close Layer }); |
Fadeout () method
Definitions and usage
The Fadeout () method uses the fade effect to hide the selected element, if the element is hidden.
Grammar
$ (selector). fadeout (Speed,callback)
Definitions and usage
The FadeIn () method uses a fade effect to display the selected element, if the element is hidden.
Grammar
$ (selector). FadeIn (Speed,callback)
Tips and comments
Tip: If the element is already displayed, the effect does not change unless the callback function is specified.
Note: This effect applies to elements that are hidden through jQuery, or elements that declare display:none in CSS (but not for visibility:hidden elements).