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

204
Visualizações
How to create infinity horizontal scroller

There is a component:

const HorizontalScroller = (props) => {

    return (
        <div className={'scroller scroller_horizontal'}>
            <div className='scroller_horizontal_child'>
                <div className="card" style={{width: '232px', height: '373px', margin: '0 20px', border: '1px solid red'}}>
                    Card
                </div>
<div className="card" style={{width: '232px', height: '373px', margin: '0 20px', border: '1px solid red'}}>
                    Card
                </div>
<div className="card" style={{width: '232px', height: '373px', margin: '0 20px', border: '1px solid red'}}>
                    Card
                </div>
<div className="card" style={{width: '232px', height: '373px', margin: '0 20px', border: '1px solid red'}}>
                    Card
                </div>
<div className="card" style={{width: '232px', height: '373px', margin: '0 20px', border: '1px solid red'}}>
                    Card
                </div>
            </div>
            <div className="scroller_horizontal_point scroller_horizontal_point_right"/>
            <div className="scroller_horizontal_point scroller_horizontal_point_left"/>
        </div>
    );
};

The number of cards is arbitrary

How to make it so that when you click on the right point, the cards shift to the left. Similarly with the other point. And this should happen endlessly It is advisable to use the transform property

Here is a picture of what should happen when you click on the right point.

pic.1

I tried to move the elements in the DOM, but the onclick method on the card did not work

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

This code is an example of a scrolling motion code that I had the same problem some time ago. I hope it helps you solve the problem.
You can see the result in this link

HTML


<div style="width:200px;overflow-x:scroll;position:relative" id="parent">
  
  <div style="width:600px;height:50px;background:red;display:inline-block;left:10px"></div>
  <div style="width:200px;height:50px;background:blue;display:inline-block"></div>
  <div style="width:200px;height:50px;background:green;display:inline-block"></div>

</div>

<button onclick="moveRight()"> right </button>
<button onclick="moveLeft()"> left </button>
  

javascript

function moveRight(){
  const parent= document.getElementById('parent');
move(parent,1);
 
}

function move(element,direction){
    let xTotalMove=30;
  let intervalId= setInterval(function(){
   if(xTotalMove>0){
     if(direction>0)
    element.scrollBy(1,0);
     else if(direction < 0)
       element.scrollBy(-1,0);
    xTotalMove--;     
   }
    if(xTotalMove==0)
      clearInterval(intervalId);
    
 },10);
}
function moveLeft(){
  const parent= document.getElementById('parent');
move(parent,-1);
}
about 4 years ago · Juan Pablo Isaza Relatório
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