JavaScript to determine whether the image has been loaded.

Source: Internet
Author: User

JavaScript to determine whether the image has been loaded.

There are a lot of articles on the Internet that determine whether the image has been loaded, but some browsers are not suitable. The following small series will share with you some summary about how JavaScript judges whether the image has been loaded, the specific content is as follows:

I. onload event

By listening to the onload event of an image, you can determine whether the image has been loaded and is compatible with all browsers (w3c recommended method). The code example is as follows:

<! DOCTYPE html> 

Ii. Determine the complete attribute of the img object (DOM)

After the img is loaded, the attribute of the complete object changes to true. The code example is as follows:

<! DOCTYPE html> 

This method is also compatible with all browsers.

3. onreadystatechange event

In ie, the img object has an onreadystatechange event like the xhr object. You can use Guo jianting's event to determine whether the image is loaded. The sample code is as follows:

<!DOCTYPE html>

This method is only available in ie

Articles you may be interested in:
  • How to determine whether the image is loaded and obtain the Image Width by JS
  • Implementation principle and process of rolling delayed loading of images on native Js pages
  • Implementation methods and ideas of js image delayed Loading
  • Examples of javascript pre-loaded images, css, and js
  • Efficient image pre-loading using CSS, JavaScript, and Ajax
  • How to Use the jquery plug-in lazyload. js to delay image loading
  • Use JavaScript to determine whether the image is loaded
  • Js implements the display of the words loaded before the image is loaded.

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.