Mouvement & Interactivité

CSS Animations

Donnez vie à vos interfaces avec des animations fluides et performantes. Transitions, keyframes, et micro-interactions pour une UX exceptionnelle.

✨ Smooth Transitions
🎭 Keyframe Magic
⚡ GPU Accelerated

Pourquoi Animer vos Interfaces ?

🎯 Meilleure UX

+40% engagement

Avantages :

  • • Guidage visuel naturel
  • • Feedback immédiat
  • • Perception de rapidité
  • • Réduction du stress cognitif

⚡ Performance

60 FPS

Optimisations :

  • • GPU acceleration
  • • Transform & opacity seulement
  • • will-change property
  • • Reduced motion support

🎨 Identité

Unique & Mémorable

Impact :

  • • Personnalité de marque
  • • Différenciation concurrentielle
  • • Émotions positives
  • • Mémorisation renforcée

🔄 Transitions vs Animations

T Transitions CSS

/* Transition simple */
.button {
  background: #3b82f6;
  transition: all 0.3s ease;
}

.button:hover {
  background: #2563eb;
  transform: translateY(-2px);
}
✅ Utiliser pour :
  • • Hover effects
  • • Focus states
  • • Show/hide elements
  • • Simple state changes

A Animations CSS

/* Animation avec keyframes */
@keyframes bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-20px); }
}

.bouncy {
  animation: bounce 1s infinite;
}
🚀 Parfait pour :
  • • Animations automatiques
  • • Loops infinies
  • • Séquences complexes
  • • Loading animations

Transitions CSS - Les Fondamentaux

⚙️ Propriétés de Transition

Testez les propriétés :

Hover Me!
transition: all 0.3s ease 0s;
/* property | duration | timing-function | delay */
transition-duration
Durée de l'animation
transition-timing-function
Courbe d'accélération
transition-property
Propriété à animer
transition-delay
Délai avant démarrage

📈 Timing Functions (Easing)

Comparez les courbes d'animation :

🚀
transition-timing-function: ease;
/* Cliquez sur les boutons pour tester */

💡 Guide des Timing Functions :

  • linear : Vitesse constante
  • ease : Démarrage rapide, ralentissement
  • ease-in : Démarrage lent
  • ease-out : Fin lente
  • ease-in-out : Début et fin lents
  • cubic-bezier() : Courbes personnalisées

🔄 Propriétés Transform

Explorez les transformations :

Transform!
transform: none;
/* Cliquez sur les boutons pour voir les transformations */

Keyframes & Animations CSS

🎭 Bibliothèque d'Animations

Testez les animations prédéfinies :

Animate!
/* Sélectionnez une animation */
animation: none;

🎨 Créer des Keyframes

Syntaxe des keyframes :

/* Définition des keyframes */
@keyframes slideIn {
  0% {
    transform: translateX(-100%);
    opacity: 0;
  }
  50% {
    transform: translateX(10px);
    opacity: 0.8;
  }
  100% {
    transform: translateX(0);
    opacity: 1;
  }
}

/* Application de l'animation */
.element {
  animation: slideIn 1s ease-out;
}

Propriétés d'animation :

/* Syntaxe complète */
.element {
  animation-name: slideIn;
  animation-duration: 1s;
  animation-timing-function: ease-out;
  animation-delay: 0.2s;
  animation-iteration-count: infinite;
  animation-direction: alternate;
  animation-fill-mode: forwards;
  animation-play-state: running;
}

/* Raccourci */
.element {
  animation: slideIn 1s ease-out 0.2s infinite alternate forwards;
}

🔧 Propriétés clés :

animation-iteration-count :
• 1, 2, 3... (nombre)
• infinite (infini)
animation-direction :
• normal (défaut)
• reverse, alternate
animation-fill-mode :
• none (défaut)
• forwards, backwards, both
animation-play-state :
• running (défaut)
• paused

⏳ Animations de Chargement

Loaders populaires :

Spinner
Dots
Pulse
Bounce
/* Spinner simple */
.spinner {
  border: 4px solid #f3f3f3;
  border-top: 4px solid #3b82f6;
  border-radius: 50%;
  animation: spin 1s linear infinite;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

Exemples Pratiques

👆 Micro-interactions

Boutons interactifs :

/* Bouton avec effet shimmer */
.btn-shimmer {
  position: relative;
  overflow: hidden;
  background: #3b82f6;
  transition: transform 0.1s ease;
}

.btn-shimmer::before {
  content: '';
  position: absolute;
  top: 0;
  left: -100%;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.2), transparent);
  transition: left 0.5s ease;
}

.btn-shimmer:hover::before {
  left: 100%;
}

.btn-shimmer:active {
  transform: scale(0.95);
}

Démo interactive :

💡 Testez : Hover et clic sur les boutons

📄 Transitions de Page

/* Animations d'entrée de page */
.page-enter {
  opacity: 0;
  transform: translateY(30px);
  animation: pageEnter 0.6s ease-out forwards;
}

@keyframes pageEnter {
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* Animation séquentielle */
.stagger-item:nth-child(1) { animation-delay: 0.1s; }
.stagger-item:nth-child(2) { animation-delay: 0.2s; }
.stagger-item:nth-child(3) { animation-delay: 0.3s; }

Démo staggered animation :

Element 1
Element 2
Element 3

⚡ Optimisation Performance

✅ Bonnes pratiques :

/* Propriétés performantes */
.optimized {
  transform: translateX(100px); /* ✅ GPU */
  opacity: 0.5; /* ✅ GPU */
  will-change: transform, opacity; /* ✅ Prépare GPU */
}

/* Support reduced motion */
@media (prefers-reduced-motion: reduce) {
  * {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

❌ À éviter :

/* Propriétés coûteuses */
.expensive {
  left: 100px; /* ❌ Layout */
  width: 200px; /* ❌ Layout */
  height: 100px; /* ❌ Layout */
  background: #ff0000; /* ❌ Paint */
  box-shadow: 0 0 10px red; /* ❌ Paint */
}
🚫 Propriétés lentes :
  • • left, right, top, bottom
  • • width, height
  • • padding, margin
  • • background, color
  • • box-shadow, border
  • • text-shadow, filter

🎯 Performance Checklist :

  • ✅ Utilisez transform et opacity
  • ✅ Ajoutez will-change avant l'animation
  • ✅ Supprimez will-change après
  • ✅ Testez sur mobile/slow devices
  • ✅ Respectez prefers-reduced-motion
  • ✅ Limitez le nombre d'animations simultanées
  • ✅ Utilisez les DevTools Performance
  • ✅ Visez 60 FPS constant
  • ✅ Préférez CSS aux animations JS

Exercices Pratiques

🎮 Exercice : Interface de Jeu Animée

🎯 Mission Complète :

Créez une interface de jeu mobile complète avec des animations fluides et des micro-interactions engageantes.

📋 Éléments à animer :

  • Splash screen avec logo animé
  • Menu principal : boutons avec effets hover
  • Barre de vie qui pulse et change de couleur
  • Score counter avec animation de comptage
  • Power-ups avec rotation et glow effects
  • Notifications slide-in/slide-out
  • Loading states pour les transitions
  • Celebration effects pour les victoires

🎨 Techniques requises :

  • • Animations CSS avec keyframes
  • • Transitions fluides entre états
  • • Timing functions personnalisées
  • • Animations séquentielles (stagger)
  • • Performance optimisée (60 FPS)
  • • Support reduced motion

🎮 Mockup Interface :

SUPER GAME
Health:
Score: 12,450
🔥
💎
+100 XP!

🚀 Template de Base

<!DOCTYPE html> <html lang="fr"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Game UI - Animation Exercise</title> <style> * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: 'Arial', sans-serif; background: linear-gradient(135deg, #1a1a2e, #16213e, #0f3460); color: white; min-height: 100vh; overflow-x: hidden; } /* Splash Screen */ .splash-screen { position: fixed; top: 0; left: 0; width: 100%; height: 100%; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); display: flex; justify-content: center; align-items: center; z-index: 1000; /* TODO: Animation d'apparition et disparition */ } .logo { font-size: 3rem; font-weight: bold; text-transform: uppercase; /* TODO: Animation de logo (scale + rotate + glow) */ } /* Game Container */ .game-container { max-width: 400px; margin: 0 auto; padding: 2rem; /* TODO: Animation d'entrée de page */ } /* Header avec titre */ .game-title { text-align: center; font-size: 2rem; font-weight: bold; margin-bottom: 2rem; background: linear-gradient(45deg, #f1c40f, #e67e22); -webkit-background-clip: text; -webkit-text-fill-color: transparent; /* TODO: Animation de pulsation et brillance */ } /* Barre de vie */ .health-container { margin-bottom: 2rem; } .health-label { font-size: 0.9rem; margin-bottom: 0.5rem; opacity: 0.8; } .health-bar { background: rgba(255,255,255,0.1); height: 20px; border-radius: 10px; overflow: hidden; position: relative; } .health-fill { height: 100%; background: linear-gradient(90deg, #e74c3c, #f39c12, #2ecc71); border-radius: 10px; transition: width 0.5s ease; /* TODO: Animation de pulsation basée sur le niveau */ } /* Score animé */ .score-container { text-align: center; margin-bottom: 2rem; } .score-value { font-size: 2.5rem; font-weight: bold; color: #f1c40f; /* TODO: Animation de comptage + bounce lors des gains */ } /* Power-ups */ .powerups-container { display: flex; justify-content: center; gap: 1rem; margin-bottom: 2rem; } .powerup { width: 60px; height: 60px; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 1.5rem; cursor: pointer; transition: all 0.3s ease; /* TODO: Animations différentes pour chaque power-up */ } .powerup-lightning { background: linear-gradient(135deg, #3498db, #2980b9); /* TODO: Animation de rotation */ } .powerup-fire { background: linear-gradient(135deg, #e74c3c, #c0392b); /* TODO: Animation de flamme (scale + glow) */ } .powerup-gem { background: linear-gradient(135deg, #9b59b6, #8e44ad); /* TODO: Animation de brillance */ } /* Boutons de jeu */ .game-buttons { display: flex; flex-direction: column; gap: 1rem; } .btn { padding: 1rem; border: none; border-radius: 12px; font-size: 1.1rem; font-weight: bold; cursor: pointer; position: relative; overflow: hidden; transition: all 0.2s ease; /* TODO: Micro-interactions (hover + active) */ } .btn-primary { background: linear-gradient(135deg, #2ecc71, #27ae60); color: white; } .btn-secondary { background: linear-gradient(135deg, #3498db, #2980b9); color: white; } /* Notifications */ .notification { position: fixed; top: 2rem; right: 2rem; background: linear-gradient(135deg, #f39c12, #e67e22); color: white; padding: 0.8rem 1.2rem; border-radius: 25px; font-weight: bold; transform: translateX(100%); /* TODO: Animation slide-in/slide-out */ } /* Loading spinner */ .loading { display: none; position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%); z-index: 999; } .spinner { width: 50px; height: 50px; border: 4px solid rgba(255,255,255,0.3); border-top: 4px solid #f1c40f; border-radius: 50%; /* TODO: Animation de rotation */ } /* Keyframes à définir */ /* TODO: @keyframes pour splash screen */ /* TODO: @keyframes pour logo animation */ /* TODO: @keyframes pour health bar pulse */ /* TODO: @keyframes pour score counting */ /* TODO: @keyframes pour power-ups effects */ /* TODO: @keyframes pour notifications */ /* TODO: @keyframes pour celebration effects */ /* Responsive */ @media (max-width: 480px) { .game-container { padding: 1rem; } .game-title { font-size: 1.5rem; } .powerup { width: 50px; height: 50px; font-size: 1.2rem; } } /* Accessibility */ @media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; } } </style> </head> <body> <!-- Splash Screen --> <div class="splash-screen" id="splashScreen"> <div class="logo" id="logo">Super Game</div> </div> <!-- Game UI --> <div class="game-container" id="gameContainer"> <h1 class="game-title">Super Game</h1> <!-- Health Bar --> <div class="health-container"> <div class="health-label">Health:</div> <div class="health-bar"> <div class="health-fill" id="healthFill" style="width: 75%;"></div> </div> </div> <!-- Score --> <div class="score-container"> <div class="score-value" id="scoreValue">0</div> <div style="font-size: 0.9rem; opacity: 0.7;">Score</div> </div> <!-- Power-ups --> <div class="powerups-container"> <div class="powerup powerup-lightning" id="powerupLightning">⚡</div> <div class="powerup powerup-fire" id="powerupFire">🔥</div> <div class="powerup powerup-gem" id="powerupGem">💎</div> </div> <!-- Game Buttons --> <div class="game-buttons"> <button class="btn btn-primary" id="playBtn">PLAY GAME</button> <button class="btn btn-secondary" id="settingsBtn">Settings</button> <button class="btn btn-secondary" id="leaderboardBtn">Leaderboard</button> </div> </div> <!-- Notification --> <div class="notification" id="notification">+100 XP Earned!</div> <!-- Loading --> <div class="loading" id="loading"> <div class="spinner"></div> </div> <script> // TODO: JavaScript pour déclencher les animations // Splash screen animation function hideSplashScreen() { // TODO: Implémenter la disparition du splash screen } // Score animation function animateScore(targetScore) { // TODO: Animation de comptage du score } // Health bar animation function updateHealth(percentage) { // TODO: Animer la barre de vie } // Notification system function showNotification(message) { // TODO: Afficher une notification animée } // Power-up effects function activatePowerup(type) { // TODO: Animation d'activation des power-ups } // Initialize game setTimeout(hideSplashScreen, 3000); setTimeout(() => animateScore(12450), 4000); </script> </body> </html>

Maîtrisez les Animations CSS ! ✨

Vous avez maintenant toutes les clés pour créer des interfaces vivantes et engageantes. Transitions fluides, animations spectaculaires et performances optimisées !

🎯 Performance

Transform & opacity pour 60 FPS garantis

♿ Accessibilité

Respectez prefers-reduced-motion

🎨 Créativité

Micro-interactions pour l'engagement