From b1e2d471521c94a99dbef6c3b4ffa33d470fadf6 Mon Sep 17 00:00:00 2001 From: Brad Traversy Date: Sun, 15 Aug 2021 18:50:23 -0400 Subject: [PATCH] Update script.js --- image-carousel/script.js | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/image-carousel/script.js b/image-carousel/script.js index 8ec8775..2d0532c 100644 --- a/image-carousel/script.js +++ b/image-carousel/script.js @@ -4,7 +4,7 @@ const rightBtn = document.getElementById('right') const img = document.querySelectorAll('#imgs img') -let idx = 1 +let idx = 0 let interval = setInterval(run, 2000) @@ -15,34 +15,12 @@ function run() { function changeImage() { if(idx > img.length - 1) { - idx = img.length - 1 - - imgs.style.transition = 'all, linear, 1s'; - imgs.style.transform = `translateX(${-idx * 500}px)` - - setTimeout(function() { - idx = 1; - imgs.style.transition = ''; - imgs.style.transform = `translateX(${-500}px)` - },0) - } - else if(idx < 0){ idx = 0 - - imgs.style.transition = 'all, linear, 1s'; - imgs.style.transform = `translateX(${-idx * 500}px)` - - setTimeout(function() { - idx = img.length - 2; - imgs.style.transition = ''; - imgs.style.transform = `translateX(${-idx * 500}px)` - },0) + } else if(idx < 0) { + idx = img.length - 1 } - else{ - imgs.style.transition = 'all, linear, 1s'; - imgs.style.transform = `translateX(${-idx * 500}px)` - } - + + imgs.style.transform = `translateX(${-idx * 500}px)` } function resetInterval() { @@ -60,4 +38,4 @@ leftBtn.addEventListener('click', () => { idx-- changeImage() resetInterval() -}) \ No newline at end of file +})