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

139
Views
Is there a way to calculate how long it will take for a smooth scroll to end

I want my animation to run after the screen has stopped scrolling in Javascript, otherwise the user won't be able to see it. Unfortunately, the speed of scrolling in chrome can vary a lot, and I don't know how to calculate the speed.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Instead of calculating the scroll duration, why not just start the animation once you detect the page is in the right scroll location? You can use window.scrollY to get the current vertical scroll of the page, and element.offsetTop to get the top position of the element.

You can make a function to check if the element is visible on the page with something like the following code.

function elementInScrolledView(element) {
    const pageTop = window.scrollY;
    const pageBottom = pageTop + window.innerHeight;

    const elementTop = element.offsetTop;
    const elementBottom = elementTop + element.offsetHeight;

    return ((elementBottom <= pageBottom) && (elementTop >= pageTop));
}

This code might need some edits if the element is taller than the window; you could compare just the tops of the elements?

You could start an interval checking each frame once the scrolling started until the function returned true, at which point you could clear the interval and start the animation.

about 4 years ago · Santiago Trujillo 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!