javascript - Does setting image's source also load the source? -
say have following code:
var img = document.createelement('img'); img.src = 'https://somepicture.png';
does image loaded source's data if don't append image dom? in other words, can make callback using img.onload()
run if don't show image user?
yes, setting source attribute load image.
you can attach load event image, , setting source attribute if not on page common approach used when preloading images prevent tearing on page during image swap.
4.7.1 img element
in browsing context scripting disabled, user agents may obtain images or on demand. in browsing context scripting enabled, user agents must obtain images immediately.
a user agent obtains images must synchronously update image data of img element whenever element created src attribute. user agent obtains images must synchronously update image data of img element whenever element has src or crossorigin attribute set, changed, or removed.
https://www.w3.org/tr/html5/embedded-content-0.html#the-img-element
Comments
Post a Comment