javascript – How to upload images one by one


I have a website and it has an image slider. When the page is loaded, the photos are loaded at the same time (for example, you watch the first slide, and it is still loading, and so on all the images). How can I make them load one by one?


Like this:


function load(imgs) {
  let img = imgs.shift();
  imgs.length && (img.onload = img.onerror = load.bind(0, imgs));
  img.src = img.dataset.src;
<img data-src=""/>
<img data-src=""/>
<img data-src=""/>
Scroll to Top