Home > Web Front-end > JS Tutorial > Problems encountered when using the image onload event of js_javascript skills

Problems encountered when using the image onload event of js_javascript skills

WBOY
Release: 2016-05-16 16:42:03
Original
1353 people have browsed it

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;
};
Copy after login

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.

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