Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

76
Visualizações
How to create button in javascript to preform flip of card on click

.thecard:hover { transform: rotateY(180deg) }

I want to perform this transform when the user will click on the card. I want to know how to make a javascript button that can perform this function when the user will click on a card.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

you can make use of the the Javascript API element.animate() to add your keyframe animations and set how you want them to work. I would advise using a site like caniuseto see what browsers are compatible with the API.

let animation = document.getElementById("card")

//If you just want to click on the card to flip it
animation.addEventListener("click", turnCard)

function turnCard (){
animation.animate([
  // keyframes
  { transform: 'perspective(400px) rotateY(0)' }, 
  { transform: 'perspective(400px) rotateY(180deg)' }
], { 
  // timing options
  duration: 1000,
  iterations: 1
})
}


//Using a button to flip the card
const cardFlipper = () =>{
  animation.animate([
  { transform: 'perspective(400px) rotateY(0)' }, 
  { transform: 'perspective(400px) rotateY(180deg)' }
], { 
  duration: 1000,
  iterations: 1
})
}
#card{
  height: 400px;
  background-color: blue;
  width: 200px;
}
<div id="card">
 </div>
  <button onclick="cardFlipper()">Flip Card</button>

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda