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

314
Vistas
Using Anime.JS, how do I apply an animation to specific elements/paths of an svg?

I've written some code that rotates the entirety of the svg, but I don't know how to rotate the individual bodies.

<!DOCTYPE html>
<html lang="en">

<head>
  <div class="content">

    <object id="demo-svg" data="./assets/test-graphic.svg" type="image/svg+xml" width="100%" height="100%"></object>

    <script src="https://cdn.jsdelivr.net/npm/animejs@3.0.1/lib/anime.min.js"></script>

    <script type="text/css">

      body, html{ margin:0 } svg, g { transform-origin: unset unset; } path { transform-origin: 50% 50%; transform-box: fill-box; }

    </script>
  </div>

</head>

<div>

  <script>
    anime({
      targets: 'path',
      scale: [0.1, 1],
      opacity: [0.1, 1],
      rotate: "1turn",
      duration: 7000
    });
  </script>


</div>

</html>

The total svg code is much too large to paste in, so here's a snippet

<linearGradient id="linear-gradient" x1="69" y1="559.5" x2="1875" y2="559.5" gradientUnits="userSpaceOnUse"><stop offset="0" stop-color="#22b226"/><stop offset="1" stop-color="#2112b5"/>

for context, this gradient pairs to the path below.

<path d="M657,540a3,3,0,0,0-3,3v33a3,3,0,0,0,6,0V543A3,3,0,0,0,657,540Z" transform="translate(-69 -56)" fill="url(#linear-gradient)"/>
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you want to target an individual part, target an individual part. Give them an ID or some other means of referring to them and go nuts.

var tl = anime.timeline({
    duration: 700,
    easing: "easeOutElastic(1, 1)",
    endDelay: 400,
    loop: true
  })
  .add({
    targets: "svg",
    scale: [0, 1]
  })
  .add({
    targets: ".eye",
    scaleY: [1, 0, 1, 0, 1],
    easing: "easeInOutSine"
  });

for (i = 0; i < 10; i++)
  tl.add({
    targets: ".pupil",
    translateX: anime.random(-12, 12),
    translateY: anime.random(-12, 12)
  });

tl.add({
  targets: "svg",
  scale: 0,
  easing: "easeInElastic(1, 1)",
  endDelay: 1000
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js"></script>
<svg width="100vmin" height="100vmin" viewBox="0 0 120 120">
  <circle cx="60" cy="60" r="40" stroke-width="6" stroke="#1F1F1F" fill="#AF87CC" transform-origin="60 60" />
  <g class="eye" transform-origin="60 60">
    <circle class="pupil" cx="60" cy="60" r="24" />
    <circle cx="77" cy="43" r="10" fill="#FFFFFF" />
  </g>
</svg>

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