The problems encountered in using the image onload event of JS _javascript skills

Source: Internet
Author: User

The onload event about the Image object.

What you want to get is the width and height value of the image. So use the OnLoad method. In addition, a remote picture is obtained.

But IE in the second display of pictures, always do not go to the OnLoad method. Code:

var img = new Image ();
IMG.SRC = "Loading.gif";
Img.onload = function () {
var iheight = img.height;
var iwidth = img.width;

Later to Xiaoniu students read, IMG.SRC should be placed in the OnLoad method behind.

Later Google, only to find that the original such problems are summed up. I'm a real amateur.

Because IE does not trigger the OnLoad method when loading the buffer data, it causes the code in the event to be ignored. FF triggers the OnLoad method when it loads the buffer data.

In fact, it is also a bit, is the onload when the picture to adapt to adjust, found that need to be in the onload also to set the element once img.src ... Or it just remembers the first picture ...

There is still a smattering of this buffer. Go on.

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.