Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR HTML

javascript wait image load complete

const loadImage = src =>
  new Promise((resolve, reject) => {
    const img = new Image();
    img.onload = () => resolve(img);
    img.onerror = reject;
    img.src = src;
  })  
;

const imageUrls = [
  "http://placekitten.com/85/150",
  "http://placekitten.com/85/130",
  "http://placekitten.com/85/110",
];
Promise.all(imageUrls.map(loadImage)).then(images => {
  const canvas = document.createElement("canvas");
  document.body.appendChild(canvas);
  const ctx = canvas.getContext("2d");
  images.forEach((image, i) =>
    ctx.drawImage(image, i * 90, 0, image.width, image.height)
  );
});
Kod parçacığını çalıştır
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #wait #image #load #complete
ADD COMMENT
Topic
Name
2+4 =