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

247
Views
Autoplay in slider with js

let left = document.querySelector('.left');
let right = document.querySelector('.right');
let img = document.querySelector('.imgs');
let imgs = document.querySelectorAll('img');

let index = 0;


function rightimg() {
  right.addEventListener('click', function () {
    index++;
    if (index > imgs.length - 1) {
      index = 0;
    }
    img.style.transform = `translateX(${-index * 500}px)`;
    console.log(img);
  });
}

// setInterval(rightimg, 2000);

left.addEventListener('click', function () {
  index--;
  if (index < 0) {
    index = imgs.length - 1;
  }
  img.style.transform = `translateX(${-index * 500}px)`;
  console.log(img);
});
Hi friends, I want to make autoplay image in this slider but setInterval is not working, can you say what is wrong in here? Thank you

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your function adds an eventlistener but it will only work when there will be an event(which is click in this case)

You can use swiperjs, it has many types of features and framework/library implentations. https://swiperjs.com/swiper-api

about 4 years ago · Juan Pablo Isaza Report
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!