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?
高洛峰2017-06-28 09:24:52
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
PHP中文网2017-06-28 09:24:52
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.
伊谢尔伦2017-06-28 09:24:52
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.
黄舟2017-06-28 09:24:52
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.