Home > Web Front-end > JS Tutorial > body text

Solve the problem of jQuery dynamically obtaining the height and width of the mobile phone screen_jquery

WBOY
Release: 2016-05-16 16:49:38
Original
1399 people have browsed it

Today I helped a colleague solve the problem of using jQuery to obtain dynamic mobile phone screen width and height.

The cause of the problem is that when a colleague uses a picture control that requires full-screen scrolling, he needs to obtain the height of the screen to set the picture to full screen. But he couldn't get the height for the first time using $(window).height(). It could be done after refreshing. I tried using window.onload=function(){} to solve the problem, but found that it still failed.

Finally, I thought it must be because the browser had a cache when refreshing for the second time, so it could get the high value. Then it must be the time difference in loading the DOM of the page that caused this problem, so I used setTimeout(method name, 500); After a delay of 500 milliseconds, the result is normal.

So when friends can’t get the screen width and height, you might as well try this

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template