jquery - How to guarantee image load before my JavaScript runs? -
jquery - How to guarantee image load before my JavaScript runs? -
i trying use
img.onload = function() { ... }
to guarantee image loaded in order proceed steps. method not work me because need load image after first 1 has been loaded (i have array of pictures must loaded, 1 after another, specific time interval).
is there alternative (maybe jquery) guarantee image loaded?
from jquery documentation: load event sent element when , sub-elements have been loaded. event can sent element associated url: images, scripts, frames, iframes, , window object.
so create wrapper div around images, , that:
$( "#imagewrap" ).load(function() { // next steps go here });
---edit---
since load event may not fire correctly, stumbled upon one: javascript: know when image loaded
$.fn.imageload = function(fn){ this.load(fn); this.each( function() { if ( this.complete && this.naturalwidth !== 0 ) { $(this).trigger('load'); } }); }
would improve solution!
javascript jquery html performance
Comments
Post a Comment