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

98
Views
css animation is running even when i switch tabs

I made a loop for a simple animation on my website, and it is running when i switch tabs. the rest of my website does not do this, so that one difference messes everything up. Is there any way i can make it only run when i am on my website-tab?

Code for the animation:

var i = 1;

function loop1() {
        setTimeout(function () {
            document.getElementById("dollarAnim").animate([
                { opacity: "0" },
                { opacity: "1" },
                { opacity: "0" },
            ], {
                duration: 10000,
                iterations: 1,
            });
            if (i > 0) {
                loop1();
            }

        }, 20000)
    }

    loop1();
<div id="dollarAnim" style="opacity: 0;">$</div>

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

you can add an event listener to window, when the user leaves:

window.addEventListener("blur", function stopAnimation(){});

and when focus again start animation:

window.addEventListener("focus", function sartAnimation(){});
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!