Update script.js

pull/149/head
SaMisUP 3 years ago committed by GitHub
parent 236f68461b
commit 9d40d82491
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -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()
})

Loading…
Cancel
Save