Home  >  Article  >  Web Front-end  >  Solve the problem of jQuery dynamically obtaining the height and width of the mobile phone screen_jquery

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

WBOY
WBOYOriginal
2016-05-16 16:49:381396browse

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

Statement:
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