javascript - What is the difference between Img.complete and img.onload to determine when the image is loaded?
PHP中文网
PHP中文网 2017-06-28 09:22:52
0
4
1067

What is the difference between the two to determine whether the image is loaded? Generally, the onload event will be called back when the loading is completed. Is img.complete still necessary?

PHP中文网
PHP中文网

认证0级讲师

reply all(4)
小葫芦

img.complete is a property of the Image object and returns a Boolean value; img.onload is an event triggered after the image is loaded

Ty80

Of the two, only img.complete can determine whether the image has been loaded. img.onload cannot determine whether the image has been loaded. Instead, after the loading is completed, the function bound to onload is directly run.

伊谢尔伦

complete is just an attribute of the HTMLImageElement object, while onload is the load event callback of the Image object. The former cannot accurately perform asynchronous callbacks when the event occurs and has some issues with browser compatibility.

黄舟

The onload property of the GlobalEventHandlers mixin is an event handler for the load event of a Window, XMLHttpRequest, <img> element, etc., which fires when the resource has loaded.
The onload event will be released when img is loaded, src The image is loaded asynchronously. If the loading is completed before the binding event, the onload event will not be triggered.
img.complete is a property that always exists and is true after loading is complete.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!