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

122
Views
React scroll animation flickery

I created a simple scroll animation to fill a vertical timeline based on the scrolling position. Link to working example My problem is that the animation is still quite flickery, especially on mobile devices. Is there any way to make the animation more smooth? I already tried to solve this with css transition, but that didn't work.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

It’s simply because you keep changing the value instantly on scroll. I tried and made it smooth by adding a very simple css transition to App.css in the code:

* {
  transition: 150ms all;
}

Once it works, you can change the selector * to the vertical line element, because we dont want it applied to all elements right, this is only for demo.

Also another approach for this. I think by not changing height value all the time but when a certain difference is met.

For example change component to this code, maybe you can try it, at least on my PC it's smooth enough

let lastValue = 0;
function App() {
  useEffect(() => {
    const timeline = document.querySelector(".timeline");
    const timelineDraw = document.querySelector(".timeline__draw");
    const bodyRect = document.body.getBoundingClientRect();
    const timelineOffset = timeline.getBoundingClientRect().top - bodyRect.top;

    var moveIndicator = function () {
      var viewportHeight = window.innerHeight;
      var hasScrolled = window.pageYOffset;
      const scrolledFurther = hasScrolled - timelineOffset + viewportHeight / 4;
      lastValue = lastValue === 0 ? scrolledFurther:lastValue;
      if (scrolledFurther && scrolledFurther > 0) {
        if (scrolledFurther > timeline.clientHeight) {
          timelineDraw.style.height = `${timeline.clientHeight}px`;
          return;
        }
        if (Math.abs(lastValue - scrolledFurther) > 2){
          lastValue = scrolledFurther;
          timelineDraw.style.height = `${scrolledFurther}px`;
        }
        return;
      }

      timelineDraw.style.height = "0px";
    };
about 4 years ago · Juan Pablo Isaza Report
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!