JavaScript pop-up layer height unlimited vertical center compatible IE FF Chrome

Source: Internet
Author: User

Today, adjust the pop-up layer, encountered a small problem: get scrolltop value?

On the Internet to see some of the high way to get the page was rolled, document.body.scrollTop in IE FF is 0, the strange is in Chrome can.

I guess FF to be closer to IE, I used the FF 13.0.1, can be used in the previous version, this skip ...

The code is as follows Copy Code
S + + "Web page is rolled high (FF):" + document.body.scrollTop;
S + + "Web page is rolled high (ie):" + document.documentElement.scrollTop;

Code fragment:

  code is as follows copy code

var h = Document.documentelement.clientheight;//js Get window height
var t = document.body.scrolltop| | Document.documentelement.scrolltop;//js gets the high
var h2 = $ (' # ' +id) that the page was rolled over. Height ();//jq get the height of the pop-up layer
$ (' # ' +id). CSS (' Top ', (H-H2)/2+t);//jq to CSS plus top value

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.