The solution to the invalid image onload event in IE browser _javascript tips

Source: Internet
Author: User

The story mode implementation is to load only the current browsing photos and the two photos below it, loading and rendering the comment area, the picture is not loaded with a pixel image placeholder, and a loading class will display a loading background map, When the image is replaced with a real picture in the visual area, the loading class is deleted after the picture has been successfully loaded.

The problem is the last side, the test found in IE under the loading class can not be deleted, the code is as follows:

Copy Code code as follows:

IMG.SRC = _SRC;
IMG.SRC = _SRC;
Img.onload = function () {
_con.delclass (' loading ');
}

Online search, onload and definition of SRC statements should be changed order, ie from the cache to take pictures, the onload does not trigger, opera also has this problem, the correct code to modify the following
Copy Code code as follows:

Img.onload = function () {
_con.delclass (' loading ');
};
IMG.SRC = _SRC;

Immediately, it's normal.


Conclusion: The onload should be written in front of SRC, first tell the browser picture loaded to do how to deal with, and then let it to load pictures. So, not IE browser does not trigger the OnLoad event, but because the buffer is loaded too fast, it has been loaded without telling it what to do after loading. Conversely, Firefox is significantly more intelligent, after adding the onload event, the Firefox browser will detect whether the buffer has this image, and some words directly triggered this event!

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.