JavaScript to determine whether the picture has been loaded the method of summarizing _javascript tips

Source: Internet
Author: User

There are a lot of online to determine whether the picture has been loaded, but some of the browser is not suitable, the following small series to share some about JavaScript to determine whether the picture has been loaded method rollup, the specific content as follows:

I. OnLoad incident

By listening to the OnLoad event of the picture, you can determine whether the picture has been loaded, compatible with all browsers (the recommended method of the consortium), and the code example below

<! DOCTYPE html>
 
 

Two. Determine the complete property of an IMG object (DOM)

When the IMG load completes, the complete object property becomes true and the code example is as follows:

<! DOCTYPE html>
 
 

The method can also be compatible with all browsers.

Three. The onReadyStateChange incident

Under IE, the IMG object has the same onreadystatechange event as the Xhr object, which can pass Guo Jianting the event to determine whether the picture is loaded or not, and the code example is as follows:

<! DOCTYPE html>
 
 

This method is only available under IE

Related Article

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.