Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

292
Vistas
marquee animation when text overflow with react

I create a react function with useref. it will detect if the text gets overflowed and it will add a class that makes the text scroll.

here the code:

  const refSp = createRef();
  useLayoutEffect(() => {
    if (
      refSp &&
      refSp.current &&
      refSp.current.clientWidth &&
      refSp.current.scrollWidth
    ) {
      if (refSp.current.clientWidth < refSp.current.scrollWidth) {
        console.log(refSp.current.scrollWidth);
      }
    }
  }, [refSp]);

HTML code with it's css:

            <p id="artis" ref={refSp}>
              <span className="marquee">
                <span id="scorll">{items.title}</span>
              </span>
            </p>

.metadata p {
  width: 86%;
  height: 30px;
  overflow: hidden;
  white-space: nowrap;
}

.marquee {
  display: inline-block;
  height: 30px;
  position: absolute;
  overflow: hidden;
  z-index: -1;
  animation: marquee 15s linear infinite;
}

but when the text started to move outside of the container the scrollWidth number started to decrease and the marquee animation stopped.

How can I fix this?

Thank you and sorry for my bad English.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda