<div>
<img data-loop-src='[
"https://picsum.photos/150/150/?image=10",
"https://picsum.photos/150/150/?image=25",
"https://picsum.photos/150/150/?image=30"
]'>
<img data-loop-src='[
"https://picsum.photos/150/150/?image=5",
"https://picsum.photos/150/150/?image=8",
"https://picsum.photos/150/150/?image=4"
]'>
<img data-loop-src='[
"https://picsum.photos/150/150/?image=2",
"https://picsum.photos/150/150/?image=99",
"https://picsum.photos/150/150/?image=84"
]'>
</div>
<script>
document.querySelectorAll('[data-loop-src]').forEach(image => {
const list = JSON.parse(image.dataset.loopSrc);
(function timer(index = 0) {
setTimeout(() => {
if (list[index]) {
image.src = list[index];
timer(++index);
} else {
setTimeout(timer, 4000);
}
}, 200);
})();
});
</script>