Home >Web Front-end >JS Tutorial >Problems encountered when using the image onload event of js_javascript skills
About the Image object onload event.
What you want to get is the width and height of the image. So use the onload method. The other is the remote picture obtained.
But when IE displays the image for the second time, it always does not use the onload method. Code:
var img = new Image(); img.src = "loading.gif"; img.onload = function(){ var iheight = img.height; var iwidth = img.width; };
After showing it to classmate xiaoniu, I found out that img.src should be placed after the onload method. .
Later, when I googled it, I discovered that many people have summarized this kind of problem. . I'm such an outsider. .
Because IE did not trigger the onload method when loading buffer data, the code in this event was ignored. When FF loads buffer data, it triggers the onload method.
In fact, there is another point, that is, the image needs to be adaptively adjusted during onload. I found that I need to set img.src for the element in onload. . . Otherwise it only remembers the first picture. . .
I still don’t know much about this cache area. continue.