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

75
Vistas
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 Respuestas
Responde la pregunta

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 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