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

96
Views
Timer loop instead of click event

Here's a flip card that works on lick but I'd like to use a timer instead of click event. The idea is that the card is flipped every 5 seconds without clicking. Is there a way where click function can be swapped with a timer/loop without affecting the entire function or structure?

var card = document.querySelector('.card');
    card.addEventListener( 'click', function() {
      card.classList.toggle('is-flipped');
    });
.scene {
      width: 200px;
      height: 260px;
      border: 1px solid #CCC;
      margin: 40px 0;
      perspective: 600px;
    }
    
    .card {
      width: 100%;
      height: 100%;
      transition: transform 1s;
      transform-style: preserve-3d;
      cursor: pointer;
      position: relative;
    }
    
    .card.is-flipped {
      transform: rotateY(180deg);
    }
    
    .card__face {
      position: absolute;
      width: 100%;
      height: 100%;
      line-height: 260px;
      color: white;
      text-align: center;
      font-weight: bold;
      font-size: 20px;
      -webkit-backface-visibility: hidden;
      backface-visibility: hidden;
    }
    
    .card__face--front {
      background: green;
    }
    
    .card__face--back {
      background: gray;
      transform: rotateY(180deg);
    }
<div class="scene scene--card">
      <div class="card">
        <div class="card__face card__face--front">some text on the front</div>
        <div class="card__face card__face--back">some text on the back</div>
      </div>
    </div>
    <p>Click card to flip.</p>

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

0

Thats sooo simple

  • Just use interval function in js Refer Here

setTimeout(function, milliseconds)
Executes a function, after waiting a specified number of milliseconds.

setInterval(function, milliseconds)
Same as setTimeout(), but repeats the execution of the function continuously.

var card = document.querySelector('.card');

    var intervalId = window.setInterval(function(){
      card.classList.toggle('is-flipped');
}, 5000);
.scene {
      width: 200px;
      height: 260px;
      border: 1px solid #CCC;
      margin: 40px 0;
      perspective: 600px;
    }
    
    .card {
      width: 100%;
      height: 100%;
      transition: transform 1s;
      transform-style: preserve-3d;
      cursor: pointer;
      position: relative;
    }
    
    .card.is-flipped {
      transform: rotateY(180deg);
    }
    
    .card__face {
      position: absolute;
      width: 100%;
      height: 100%;
      line-height: 260px;
      color: white;
      text-align: center;
      font-weight: bold;
      font-size: 40px;
      -webkit-backface-visibility: hidden;
      backface-visibility: hidden;
    }
    
    .card__face--front {
      background: green;
    }
    
    .card__face--back {
      background: gray;
      transform: rotateY(180deg);
    }
<div class="scene scene--card">
      <div class="card">
        <div class="card__face card__face--front">front</div>
        <div class="card__face card__face--back">back</div>
      </div>
    </div>
    <p>Click card to flip.</p>

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!