1 of 10

CSS Transitions & Animations

1

We use tech to connect human potential and opportunity with dignity & humility

2 of 10

Today’s objectives

  • Introduction to animations with CSS
  • CSS Transitions
  • CSS Animations
  • Work on Final Project

2

3 of 10

Introduction to animations with CSS

3

4 of 10

Introduction to animations with CSS

4

2 common types for animations:

  1. CSS Transitions → usually used, when a user interacts with an element�
  2. CSS Animations → no need for user-interaction and more fine-grained animations possible

5 of 10

CSS Transitions

5

Transitions are typically applied when a user interacts with an element (e.g when a user hovers or clicks on an element)

To create a transition effect, you must specify:

  • Add the transition CSS property to the element you want to add an effect to
  • which CSS property should be added a transition effect to
  • the duration of the effect
  • The change of the specified CSS property on user interaction (e.g. hover)

div {

transition: background-color 0.5s ease;

background-color: red;

}

div:hover {

background-color: green;

}

6 of 10

CSS Transitions

6

7 of 10

CSS Animations

7

Animations can start directly on load of the page, but can also be triggered on interaction of the user.

CSS Animations can have more control than CSS Transitions in the steps until the end of the animation and can run indefinitely.

To create an animation effect, you must specify:

  • The animation-name and steps with the @keyframes syntax
  • Apply the created animation to a specific CSS selector with animation-name
  • Set the duration of the animation

.element {

height: 200px;

/* animation-name must match @keyframes value */

animation-name: pulse;

animation-duration: 5s;

animation-iteration-count: infinite;

}

/* @keyframes <animation-name> with <percentage> steps */

@keyframes pulse {

0% {

background-color: hotpink;

}

50% {

background-color: yellow;

}

100% {

background-color: hotpink;

}

}

8 of 10

Note

8

Should not be overused, but can be powerful if used in correct places

9 of 10

CSS Animations

9

10 of 10

Work on final project

10