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

289
Views
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
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!