JS. An image onload.

Source: Internet
Author: User

About the onload event of the Image object.

 

What you want to obtain is the width and height of the image. Therefore, the onload method is used. In addition, the remote image is obtained.

 

However, when IE displays the image for the second time, the onload method is always not used. Code:

 

Var img = new Image ();

Img. src = "loading.gif ";

Img. onload = function (){

Var iheight = img. height;

Var iwidth = img. width;

};

 

Later, I showed it to xiaoniu. I learned that img. src should be placed behind the onload method ..

 

Later, google discovered that many people had summarized such problems .. I am really a layman ..

 

Because the onload method is not triggered when IE loads the buffer data, the code in this event is ignored. FF triggers the onload method when loading the buffer data.

 

So.

 

 

In fact, there is another point, that is, when onload needs to make adaptive adjustments to the image, we find that we need to set img. src for the element again in onload... Otherwise, only remember the first image...

 

This cache zone is completely unknown .. Continue.

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.