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

158
Visualizações
Slide animation for text in container infinitely

I am working on slide animation for text in container infinitely.

However, I found it not working smoothly. When the text reaches the end, it seems like restarting instead of looping the text.

What I want is the text keep sliding to the right continuously.

How to solve it?

App.js

import "./styles.css";

export default function App() {
  return (
    <div className="App">
      <div class="slide-right">
        <h2>
          <span>A</span>
          <span>A</span>
          <span>A</span>
          <span>A</span>
          <span>A</span>
          <span>A</span>
        </h2>
      </div>
    </div>
  );
}

Styles.css

.App {
  font-family: sans-serif;
  text-align: center;
}

.slide-right {
  border: 1px solid grey;
  width: 150px;
  overflow: hidden;
}

.slide-right h2 {
  animation: infinite slide-right 2s linear;
  transform: translateX(-100%);
  text-align: right;
}

.slide-right h2 span {
  margin-right: 10px;
}

@keyframes slide-right {
  to {
    transform: translateX(0);
  }
}

Codesandbox:
https://codesandbox.io/s/hidden-bird-qy3jy?file=/src/styles.css

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

0

Change your "slide-right" keyframes from transform: translateX(0); to transform: translateX(100%);

about 4 years ago · Juan Pablo Isaza Relatório

0

@keyframes slide-right {
  to {
    transform: translateX(100%);
  }
}

Use this instead of translateX(0)

Double the number of A to make the effect continuous.

about 4 years ago · Juan Pablo Isaza Relatório

0

To get a continuous flow this snippet has two copies of the spans.

Initially the h2 is translated -50% so only the beginning of the second half is showing.

The animation moves it to the right so it ends up with the beginning of the first half showing.

Then on the repeat the beginning of the second half takes the place of the beginning of the first half, so it all looks continuous.

.App {
  font-family: sans-serif;
  text-align: center;
}

.slide-right {
  border: 1px solid grey;
  width: 150px;
  overflow: hidden;
}

.slide-right h2 {
  animation: infinite slide-right 2s linear;
  transform: translateX(-50%);
  display: inline-block;
}

.slide-right h2 span {
  margin-right: 10px;
}

@keyframes slide-right {
  to {
    transform: translateX(0);
  }
}
<div class="App"><div class="slide-right"><h2><span>A</span><span>A</span><span>A</span><span>A</span><span>A</span><span>A</span><span>A</span><span>A</span><span>A</span><span>A</span><span>A</span><span>A</span></h2></div></div>

Note: to avoid problems with wrapping of text the spans are laid out continuously (as in the codesandbox in the question).

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