There is an array:
const imgs = ['url1', 'url2', 'url3', ...];
Please achieve the effect:
Please load the pictures in the order of the picture array (Note: load one and then load the next)
const images = ['url1','url2','url3']
const loadImg = (url) => {
return new Promise(resolve => {
let image = new Image()
image.src = url
image.onload = () =>{
resolve(image)
}
image.onerror = () => {
reject(`Errors on loading`)
}
})
}
const solve = (images) => {
const imgQueue = []
for(let i = 0;i<images.length;i++) {
imgQueue.push(loadImg(images[i]))
}
Promise.all(imgQueue).then((item) => {
console.log(item)
})
}
solve(images)