Giter Club home page Giter Club logo

animations-css's Introduction

Guide complet des animations en CSS

Auteur Udemy: Axel Paris

Mouvement CSS

  • Propriété transition (via sélecteurs)
  • Propriété animation + Keyframes

Eléments animables

  • background-color
  • width / height
  • margin
  • padding
  • font-size
  • ...

Performances

exemple : Position vs Transform

Transitions gourmancdes :

  • width
  • padding
  • position
  • ...
  • color

Vos transitions performantes avec...

  • opacity
  • translate
  • rotate
  • scale

Propriété transition

.element {
  transition: <property> <duration> <timing-function> <delay>;
}

ou

.element {
  transition-property: <property>;
  transition-duration: <duration>;
  transition-timing-function: <timing-function>;
  transition-delay: <delay>;
}

exemple:

.box {
  transition: opacity 200ms ease-in 1s;
}

Timing function

Cubic bezier

.element {
  transition-timing-function: cubic-bezier(x1, x2, x3, x4);
}

Démo : cubic-bezier.com

Déclancher une transition CSS

.element:hover
.element:active
.element:focus
...
.element.classname
.element#idname
...
#button {
    opacity: 0.5;
    transition-duration 1s;
}

#button.active {
    opacity: 1;
}
var element = document.getElementById("button");
element.cla & ssList.toggleClass("active");

Mauvaise pratique :

.element {
  background-color: red;
}

.element:hover {
  background-color: blue;
  transition-duration: 1s;
}

Bonne pratique :

.element {
  background-color: red;
  transition-duration: 1s;
}

.element:hover {
  background-color: blue;
}

Mettre les transitions dans l'état initial

Exercices

Exercice 1 : Enoncé -> Corrigé

Exercice 2 : Enoncé -> Corrigé

Exercice 3 : Enoncé -> Corrigé

Exercice 4 : Enoncé -> Corrigé

Les @Keyframes

@keyframes <animation name> {
  <keyframe-selector > {
    property: value;
  }
}

exemple

@keyframes ballRebond {
  0% {
    top: 0px;
  }
  50% {
    top: 100px;
  }
  100% {
    top: 0px;
  }
}

ou

@keyframes ballRebond {
  0%,
  100% {
    top: 0px;
  }
  50% {
    top: 100px;
  }
}

ou encore

@keyframes ballRebond {
  from,
  to {
    top: 0px;
  }
  50% {
    top: 100px;
  }
}

Animer les keyframes

.elementToAnimate {
  animation-name: <animation-name>; // obligatoire
  animation-duration: <animation-duration>; //obligatoire
  animation-timing-function: <animation-timing-function>;
  animation-delay: <animation-delay>;
  animation-iteration-count: <animation-iteration-count>;
  animation-direction: <animation-direction>;
  animation-fill-mode: <animation-fill-mode>;
  animation-play-state: <animation-play-state>;
}

Outils pour créer vos keyframes

animations-css's People

Contributors

bogala avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.