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

127
Views
Run SVG Draw line animate or reverse ONLY when its container is in viewport

I have implemented a code which draws a line svg stroke from a specific position to the end of an element but what my problem is that the svg line dashoffset is being generated from the very top of my window which I want it to be triggered right after the viewport of mentioned svg container.

example: https://altsdigital.com/

var triangle = document.getElementById("star-path");
var length = triangle.getTotalLength();

triangle.style.strokeDasharray = length;

triangle.style.strokeDashoffset = length;

window.addEventListener("scroll", myFunction);

function myFunction(e) {

    var scrollpercent = (document.body.scrollTop + document.documentElement.scrollTop) / (document.documentElement.scrollHeight - document.documentElement.clientHeight);
    // console.log(scrollpercent)
    var draw = length * scrollpercent;
    triangle.style.strokeDashoffset = length - draw;
}

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!