I'm writting a slider and I need to use the tramsform style in JS code. But when I wrote it in JS, nothing happended. Could you tell me what's wrong? how to fix it? This is my js code. Please take a look at it.
const slides = document.querySelector(".slides");
const slidesCount = slides.childElementCount;
const nextBtn=document.querySelector(".next-slide");
const prevBtn=document.querySelector(".prev-slide");
const container = document.querySelector('.slider-container')
//Controls
prevBtn.addEventListener('click', () => {
changeSlide('prev')
})
nextBtn.addEventListener('click', () => {
changeSlide('next')
})
let activeSlideIndex = 0
function changeSlide(direction) {
if(direction === 'prev') {
activeSlideIndex++
if(activeSlideIndex === slidesCount) {
activeSlideIndex = 0
}
} else if(direction === 'next') {
activeSlideIndex--
if(activeSlideIndex < 0) {
activeSlideIndex = slidesCount - 1
}
}
Array.from(slides.children).forEach((slide, idx) => {
if (idx === activeSlideIndex) {
slide.classList.add('active');
} else {
slide.classList.remove('active');
}
});
const weigth= container.clientWeigth;
slides.style.transform =`translateX(${activeSlideIndex * weigth}px)
}