19 lines
656 B
JavaScript
19 lines
656 B
JavaScript
{a6bb87b189609a84ee1946443d5c0d7874f1d57d true 656 script.js 0xc002bd78f0}
const buttons = document.querySelectorAll("[data-carousel-button]")
|
|
|
|
buttons.forEach(button => {
|
|
button.addEventListener("click", () => {
|
|
const offset = button.dataset.carouselButton === "next" ? 1 : -1
|
|
const slides = button
|
|
.closest("[data-carousel]")
|
|
.querySelector("[data-slides]")
|
|
|
|
const activeSlide = slides.querySelector("[data-active]")
|
|
let newIndex = [...slides.children].indexOf(activeSlide) + offset
|
|
if (newIndex < 0) newIndex = slides.children.length - 1
|
|
if (newIndex >= slides.children.length) newIndex = 0
|
|
|
|
slides.children[newIndex].dataset.active = true
|
|
delete activeSlide.dataset.active
|
|
})
|
|
})
|