The form of the JQuery pop-up window has always been the center of a specific case

Source: Internet
Author: User

On-line Chado is not a non-conforming void; therefore, some self-summary to solve this problemprinciples:FAQ: Pop-up layer is centered, the background is translucent but found a pull scroll bar immediately revealed that the background is only set the screen, the other parts are the original appearance, and the pop-up layer because the scroll bar movement is missing this is the majority of online pop-up layer of the common problem solving method, There are three kinds of 1. Using the IE6 vulnerability, _top and using CSS expresstion expression strengths: No jitter, by calculating the location, most browsers can use the disadvantage: CSS expresstion is not recommended because the CSS when doing whatever event Expression will call the JS method to calculate the result again, casually have 1000 times/second, when the page element is very much rendering effect is very very poor background layer, the style of the pop-up layer willposition:fixed;

Change into

position:fixed!important;/* FF ie7*/position:absolute;/*ie6*/_top:expression (eval (Document.compatmode &&            document.compatmode== ' Css1compat ')?            Documentelement.scrolltop + (Document.documentelement.clientheight-this.offsetheight)/2:/*IE6*/            Document.body.scrollTop + (Document.body.clientheight-this.clientheight)/2);/*IE5 ie5.5*/

The 2.js method calculates the position again

$ (function () {$ (window). Scroll (function () {  //browser scroll bar invalid;  $ (window). scrolltop (0);    var offset = $ (window). offset ();  var position = $ (window). position ();  $ ("#div_pop"). CSS ("Top", $ (window). scrolltop () +$ (window). Outerheight ()/3);   Scroll bar Move height + browser height (calculate outer box) in one of the three points ("#div_back"). CSS ("height", $ (window). scrolltop () +$ (window). Outerheight ()); })  //Background layer height, scroll bar movement height + browser height (calculate outer frame)


Advantages of CSS expression to overcome a large number of elements render slow problem chrome no problem, ie jitter due to move the scroll bar to calculate the height, delay caused the pop-up window jitter (the effect is very unfriendly) 3. Fixed scroll bar keeps the pop-up layer centered with scroll bar events fixed scroll bar always 0
$ (function () {$ (window). Scroll (function () {  //browser scroll bar invalid;  
Pros: jquery's Scroll method is compatible with most browsers important is the same time screen onkeypress up and down caused by the scroll bar moved to talk about JS lock scroll bar to participate
<script> var Firefox = navigator.userAgent.indexOf (' Firefox ')! =-1; function MouseWheel (e) {///to img down mouse roll, block window scrolling e = e | | window.event; if (e.stoppropagation) e.stoppropagation (); Else e.ca Ncelbubble = true; if (E.preventdefault) E.preventdefault (); else E.returnvalue = false; Other code} window.onload = function () {var img = document.getElementById (' img '); Firefox img.addeventlistener (' dommouses Croll ', MouseWheel, False): (Img.onmousewheel = MouseWheel); } </script><div style= "height:100px" ></div>  <div style=" height:1000px "></div>


Scroll bar Event Onmousewhell Iedommousescroll FF detailed description see this link
JavaScript Mouse wheel scrolling events
But this method with onkeypress up and down keys will fail false assumption intact can add to the upper and lower key monitoring and the following method directly using Position:fixed relative to the browser offset to conquer all the above problems but note the following 3 points: 1.<! DOCTYPE html> must write, set the browser to HTML parsing version number detailed analysis can see the explanation of this blog2.set a layer with transparent backgroundz-index:9998;//Layer Settingsopacity:0.5;//ie6 's TransparencyFilter:alpha (opacity=50);//ie6 above the transparent-moz-opacity:0.5; Firefox transparency3. Set up a pop-up layerz-index:9999;//Layer SettingsPop-up layer, the background layer of the position are fixed3. Click on the button to display it or hide it.
<! DOCTYPE html>


Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

The form of the JQuery pop-up window has always been the center of a specific case

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.