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

250
Vistas
How can I target $(this) in anime.js

I am trying to achieve a click animation on a <a> tag. There are multiple <a> tags and all of them have the same class.

How do I achieve this?

As an alternative, I had tried adding a class as temporary to the targeted element using $(this).addClass('temp')

I need to know if there is a better way to actually do it.

If I go with the above method, I won't be able to bring animations with delays.

Sample

<script>
  $("a").click(function(){
    anime({
    targets:'a',
    opacity:[0,1],
    })
  });
</script>

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can simply pass e.currentTarget to the targets property (which accepts a DOM node), so that you will target the current <a> element that the event listener is bound to. Alternatively you can also pass in this: it's up to you.

See proof-of-concept below. I have tweaked the opacity to 0.25 so that you can actually see the element before clicking on it.

$("a").click(function(e) {
  e.preventDefault();
  anime({
    targets: e.currentTarget,
    opacity: [0.25, 1],
  })
});
a {
  opacity: 0.25;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="#">Click me</a>
<a href="#">Click me</a>
<a href="#">Click me</a>
<a href="#">Click me</a>
<a href="#">Click me</a>

Or just do it natively in JS without needing jQuery:

document.querySelectorAll('a').forEach(el => {
  el.addEventListener('click', e => {
    e.preventDefault();
    anime({
      targets: el,
      opacity: [0.25, 1],
    });
  });
});
a {
  opacity: 0.25;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<a href="#">Click me</a>
<a href="#">Click me</a>
<a href="#">Click me</a>
<a href="#">Click me</a>
<a href="#">Click me</a>

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