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

271
Vistas
Why does the animation keep repeating itself even when not hovering over the div?

I am using Javascript & jQuery and I have been trying to make a quick website to show to my music teacher.

When I mouse over an invisible object the animation occasionally starts twice, or repeats forever, then it shows the screen I want it to show. When I mouse off of it, it just does the normal animation back to 0px, but then for no apparent reason it does the starting animation again, then the off animation, then the start, and so on and so forth.

Here is a snippet of my code. Tell me if you need more.

$(document).ready(function() {
  $("#song1").hover(function() {
    $(this).css({
      'width': '0px',
      'height': '0px'
    })

    $(this).animate({
      width: '560px',
      height: '315px',
      opacity: '100'
    })
  }, function() {
    $(this).animate({
      width: '0px',
      height: '0px',
      opacity: '0'
    })

    $(this).css({
      'width': '560px',
      'height': '315px'
    })
  })
})
body {
  background-color: grey
}

p {
  color: white
}

#song1 {
  background-color: white;
  opacity: 0;
  width: 560px;
  height: 315px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<p id="song1tx">1.</p>
<div id="song1">
  <p id="song1load" style="color: black">Loading...</p>
</div>

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

0

Try selecting the element only if it's animating:

$(document).ready(function() {

    $("#song1:not(:animated)").hover(function() {
        $(this).css({
            'width': '0px',
            'height': '0px'
          });
      
          $(this).animate({
            width: '560px',
            height: '315px',
            opacity: '100'
          });
    });

    $("#song1").mouseout(function() {
        $(this).animate({
            width: '0px',
            height: '0px',
            opacity: '0'
          })
      
          $(this).css({
            'width': '560px',
            'height': '315px'
          })
    });

});
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