Transition sur un click

chabinot Messages postés 321 Date d'inscription mardi 10 novembre 2015 Statut Membre Dernière intervention 22 mars 2024 - 21 août 2023 à 13:06

Bonjour,

J'ai un script et je voudrais savoir comment faire une transition
sans jQuery.
Voilà un extrait de mon code actuel:
 

// Afficher body et footer au clic
cartes.forEach(carte => {
  const entete = carte.querySelector('.carte-header')
  const corps = carte.querySelector('.carte-body')
  const footer = carte.querySelector('.carte-footer')

  entete.addEventListener('click', () => {
    // Inversez l'état d'affichage du corps et du footer au clic
    corps.style.display = corps.style.display === 'flex' ? 'none' : 'flex'
    footer.style.display = footer.style.display === 'flex' ? 'none' : 'flex'
    
  })
})

J'aurais aimé avoir une transition de x secondes et un effet fade

Le CSS concerné :

.carte {
  margin-right: 10px;
  width: 330px;
  height: 240px;
}
.carte-header {
  height: 80px;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
  border-top: 1px solid #fff;
  border-right: 1px solid #fff;
  border-bottom: 1px solid #fff;
  border-left: 1px solid #fff;
  border-top-left-radius: 10px;
  border-top-right-radius: 10px;
}
.carte-header h4 {
  margin: 10px 10px;
  cursor: pointer;
}
.carte-body {
  display: flex;
  justify-content: center;
  border-left: 1px solid #fff;
  border-right: 1px solid #fff;
  border-bottom: 1px solid #fff;
}
img {
  margin-top: 10px;
  margin-bottom: 10px;
  width: 80px;
  height: 80px;
  border-radius: 50%;
}
.carte-footer {
  display: flex;
  justify-content: center;
  align-items: center;
  border-left: 1px solid #fff;
  border-right: 1px solid #fff;
  border-bottom: 1px solid #fff;
  border-bottom-left-radius: 10px;
  border-bottom-right-radius: 10px;
}
.carte-footer p {
  margin-top: 10px;
}

Merci de votre aide.

Cordialement
Windows / Chrome 116.0.0.0

A voir également: