Bad Coder
Bad Coder

Reputation: 906

Handling image onload function for multiple images

function handleonload(url , callback)
{ 
var img = new Image();


  img.onError = function() {
    alert('Cannot load image: "'+url+'"');
  };
  img.crossOrigin = '';
  img.onload = function() {
    callback(img);
  };


  img.src = url;
}
handleonload(imageurl,callbackfunction);

I am using this function for multiple images ? But i am not getting a correctly map output images some of them are repeated

Upvotes: 1

Views: 425

Answers (1)

imsky
imsky

Reputation: 3279

Try imagesLoaded: http://imagesloaded.desandro.com/

Usage is straightforward: imagesLoaded( elem, callback );

Upvotes: 1

Related Questions