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.