Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

150
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!