Today in the development of Youdao Chinese Dictionary Mobile version of the encounter a very strange problem.
When accessed on Android devices, always found that the bottom background color can not be fully rendered out of the situation (sometimes normal, a little while the appearance of a moment, the iphone device is also completely OK), is half the background, and half is not ...
After a closer look, I found that when I opened the Web page, I showed a small picture of the head and a caption, a button at the bottom, and a larger image in the middle, with a loading process.
OK, suspect that the picture has not been loaded, resulting in a height calculation error, to the bottom of the background when the loaded block is no color ...
Then use the $ (window). Load () function to fix it!
There is an explanation on the Internet:
The window load event executes a bit later when the complete page was fully loaded, including all frames, objects and images. Therefore functions which concern images or other page contents should being placed in the Load event for the window or the C Ontent tag itself.
Look like Ha, the code is as follows:
var height = document.body.clientHeight; $ ("#doc2"). CSS ("height", height+ "px"); $ ("#doc2"). CSS ("Background-color", "E84C32");
Well, no matter what, there is this phenomenon ...
Just to judge the picture, I get the first slider, and then judge its onload
var function () { var height = document.body.clientHeight; $ ("#doc2"). CSS ("height", height+ "px"); $ ("#doc2"). CSS ("Background-color", "E84C32"); } var img = $ (' #firstimg '); if (Img.prop (' complete ')) { setposition (); Else { img.load(function() {setposition ();}); }
Roar, it's done, and then you have to study why Window.load failed ... There's no problem with the iphone ...