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

99
Views
image carousel using transform property

example code: - https://jsfiddle.net/dy1vk40f/

I want to make a image carousel feature, I implemented everything with two button :- forward and backword to scroll according to the buttons. I have used scrollcontainer.style.transform = translate3d(-250px, 0px, 0px); to move the images forward and vice versa. Now I want to implement a feature where when the mouse is clicked on the container and drag to left or right, I want to again change the transform property. But I am struggling to do it properly.

I have this code, but it gives a very glitchy scroll and I don't think its the right way to do it. Is there any other, it would be great help if anyone can help

let isDown = false;
let startX;
let scrollLeft;

scrollcontainer.addEventListener('mousedown', (e) => {
    isDown = true;
    startX = e.pageX;
    console.log(startX);
});

scrollcontainer.addEventListener('mouseleave', (e) => {
  isDown = false;
});

scrollcontainer.addEventListener('mouseup', (e) => {
  isDown = false;
});

scrollcontainer.addEventListener('mousemove', (e) => {
  if(!isDown) return;
  e.preventDefault();
  
  const x = e.pageX;

  const walk = (x - startX) * 3;
  scrollcontainer.style.transform = `translate3d(${walk}px, 0px, 0px)`;
  console.log({walk, startX});
  console.log('gg');
});```
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!