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

152
Vistas
Play or pause CSS animation using JavaScript

I'm unsure if the following lines of JavaScript are correct. On the click of a button, the following JavaScript function is called. This function should pause the CSS animation when clicked once and resume the animation if clicked again:

function myFunction()
    {
        document.getElementById("sky").style.animationPlayState = "paused | running";
    }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The logic for determining what state to change it to, needs to be done outside the quotes. You are probably looking more for something like this:

function myFunction()
{
  var sky = document.getElementById("sky");
  if(sky.style.animationPlayState == "paused")
  {
    sky.style.animationPlayState = "running";
  }
  else
  {
    sky.style.animationPlayState = "running";
  }
}

Or all in one line like this:

element.style.animationPlayState = running ? 'paused' : 'running';
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