Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

100
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda