Influence of DOCTYPE on values of $ (window). height (), doctype. height

Source: Internet
Author: User

Influence of DOCTYPE on values of $ (window). height (), doctype. height

Preface:The company project needs to use a vertical center of the bullet box, similar vertical center pop-up layer on the internet is similar, because the project is based on Jquery, so use $ (window ). height ()-layer. height ()/2 + $ (document ). scrollTop () Achieves vertical displacement. After testing the various browsers, there is no problem. After the background staff moved the value to the project, there is a problem. When the page goes beyond one screen, in chrome and FF, the pop-up box is centered relative to the entire page instead of the vertical center of the current screen.

All conclusions are as follows:
1. window height, $ (window). height ()
2. document height, $ (document). height ()
3. rolled up height, $ (window). scrollTop ()

Locate the cause: Then, we found that no DOCTYPE is set for the background staff's page, so in chrome, $ (window ). height () = $ (document ). height (), $ (document ). height () indicates the height of the entire window when the actual content height of the webpage is not full (this value changes when the window is enlarged or reduced ), when the page is larger than one screen, it indicates the actual height of the content of the entire page. there is no objection, and it is not affected if no DOCTYPE is set. However: $ (window ). height () in DOCTYPE is transitional. when dtd is used, regardless of whether the actual height of the webpage content exceeds the full screen, it is equal to the height of the entire window (this value changes when the window is enlarged or reduced ), if DOCTYPE is not set, $ (window ). height () = $ (document ). height (). When the content is too large, $ (window ). height () is the actual height of the webpage, not equal to the window height.

Solution:S to get the window height, you can only make the corresponding changes based on DOCTYPE, do the following when no DOCTYPE is set
If ($ (document). height () >=$ (window). height ()){
_ Required wheight = document. body. clientHeight;
} Else {// alert ($ (window). height ());
_ Required wheight = $ (document). height ();
};
When DOCTYPE is set to transitional. dtd, export wheight = $ (window). height ()

Related Article

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.