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

123
Views
SVG one-way transition

I am trying to make an SVG element change instantly to black and then immediately start to slowly fade to white, in a repeatable fashion (if triggered again mid-fade it should jump instantly to black and start the animation over).

I can't do this with CSS because the duration value is calculated at runtime in Javascript.

I tried this:

node.style.transition = 'none';
node.style.fill = 'black';
node.style.transition = `fill ${duration}s ease-out`;
node.style.fill = 'white';

However this only works if I slightly offset the transition to white, like this:

node.style.transition = 'none';
node.style.fill = 'black';
setTimeout(() => {
    node.style.transition = `fill ${duration}s ease-out`;
    node.style.fill = 'white';
}, 10);

Otherwise the instant transition to black isn't rendered at all, and the node stays white.

Why is this happening, and can it be avoided without resorting to setTimeout?

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!