100-project-100-days-website/100_projects/40-carousel-image-vanilla-js/script.js
2023-04-02 16:30:12 +03:00
Ask

14 lines
290 B
JavaScript

{ffb9c285de3606bcd9b28ac01d137611d643971c true 290 script.js 0xc0000f91f0}

const imgs = document.getElementById("imgs");
const img = document.querySelectorAll("#imgs img");
let index = 0;
function run() {
index++;
if (index > img.length - 1) {
index = 0;
}
imgs.style.transform = `translateX(${-index * 500}px)`;
}
setInterval(run, 2000);