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