From 9d40d82491f48c6f3270e2ca760421b225a78f6e Mon Sep 17 00:00:00 2001 From: SaMisUP <93011252+SaMisUP@users.noreply.github.com> Date: Sun, 15 Jan 2023 02:30:04 +0100 Subject: [PATCH] Update script.js --- image-carousel/script.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/image-carousel/script.js b/image-carousel/script.js index 2d0532c..169fff6 100644 --- a/image-carousel/script.js +++ b/image-carousel/script.js @@ -4,23 +4,23 @@ const rightBtn = document.getElementById('right') const img = document.querySelectorAll('#imgs img') -let idx = 0 +let PO = 0 let interval = setInterval(run, 2000) function run() { - idx++ + PO++; changeImage() } function changeImage() { - if(idx > img.length - 1) { - idx = 0 + if(PO > img.length - 1) { + PO = 0 } else if(idx < 0) { - idx = img.length - 1 + PO = img.length - 1 } - imgs.style.transform = `translateX(${-idx * 500}px)` + imgs.style.transform = `translateX(${-PO * 500}px)` } function resetInterval() { @@ -29,13 +29,13 @@ function resetInterval() { } rightBtn.addEventListener('click', () => { - idx++ + PO++ changeImage() resetInterval() }) leftBtn.addEventListener('click', () => { - idx-- + PO-- changeImage() resetInterval() })