Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

124
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda