Solve jQuery's problem of dynamically obtaining cell phone screen height and width _ jquery

Source: Internet
Author: User
This article mainly introduces how to solve the problem of jQuery's dynamic acquisition of cell phone screen height and width. If you need it, you can refer to this article to help colleagues solve the problem of using jQuery to obtain dynamic cell phone screen width and height.

The cause of the problem is that when a colleague uses an image control that requires full screen scrolling, he needs to get the screen height to set the picture to full screen. But he uses $ (window ). height () cannot be obtained for the first time. After refreshing, I tried to use window. onload = function.

Finally, I think it must be because the browser has a cache during the second refresh, so we can get a high value. It must be the time difference between page loading DOM, which leads to this problem, therefore, setTimeout (method name, 500) is used; the result is normal after a delay of 500 milliseconds.

So when friends cannot get the screen width, try this.

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.