Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

129
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda