Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

133
Views
Style Transform for slider doesn't work in the js code

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

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!