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

190
Visualizações
¿Cómo hago para que SVG textPath funcione con una ruta animada?

Vea la demostración aquí: https://codepen.io/bsoutendijk/pen/gOvLMaq

Comportamiento esperado: después de hacer clic en el botón "actualizar ruta", la ruta cambiará y el texto aparecerá a lo largo de la ruta al final de la animación.

Comportamiento real: el texto aparece correctamente en la ruta al cargar, pero al hacer clic en actualizar ruta, el texto no aparece en el lugar correcto.

código:

 const path = document.getElementById('myPath'); const button = document.getElementById('myButton'); button.addEventListener('click', () => { console.log('clicked!'); path.setAttribute('d', getRandomCurve()); }) function getRandomCurve() { const curveSize = Math.round(Math.random() * 300); return `M 100 350 q ${curveSize} -300 300 0` }
 #myPath { transition: all ease-out 2s; }
 <div> <button id="myButton">Update Path</button> <svg height="400" width="450"> <path id="myPath" d="M 100 350 q 150 -300 300 0" stroke="blue" stroke-width="5" fill="none" /> <text style="font-size: 2em;"> <textPath startOffset="30%" text-anchor="middle" href="#myPath"> Hello World </textPath> </text> </svg> </div>

¿Cómo uso textPath de manera que pueda funcionar con rutas animadas?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

 const path = document.getElementById("myPath2"); function getRandomCurve() { const curveSize = Math.round(Math.random() * 300); return `M 100 350 q ${curveSize} -300 300 0`; } setInterval(() => { const pathDef = getRandomCurve(); path.setAttribute("d", pathDef); }, 1000)
 .anim { transition: 1s; }
 <div> <svg height="400" width="450"> <path id="myPath2" class="anim" d="M 100 350 q 150 -300 300 0" stroke="blue" stroke-width="5" fill="none" /> <text x="0" y="0" style="font-size: 2em;"> <textPath startOffset="30%" href="#myPath2" class="anim"> Hello World <animateTransform attributeName="transform" dur="2s" repeatCount="indefinite"/> </textPath> </text> </svg> </div>

Oh, puedo hacerlo :)

"animateTransform" puede solucionar su problema. "repeatCount" - atributo importante, intente eliminarlo y su animación se detendrá después de "dur"

about 4 years ago · Juan Pablo Isaza Relatório
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