CSS & Motion Design

CSS Transitions #

how a property should display when given a different value

Are all about going from one value to another

to write it you need two things:

transition: color 200ms ease-in 100ms;

using ms is more robust than s because JS deals with ms

An example of moving a ball

.ball {
transition: transform 500ms;
}

.playing .ball {
transform: translatex(200px);
}

then you add playing class to the body after the page is loaded

document.addEventListener("DOMContentLoaded", (event) => {
document.querySelector(".parent").classList.add("playing");
});

Transition multiple properties #

you can do this to animate all the properties

transition: all 200ms;

But wait don't!

this is not performant at all

here's a better way to do it

transition: 
transform 500ms 200ms,
color 500ms;

Duration #

Three timeframes for user attention

so for user to notice change it should be between 250ms and 300ms

Timing Function / easing #

describes an animation rate of change over time

types of timing functions

ease-in

acceleration starts slow then gets quicker

ease-out

deceleration starts quick then gets slower

ease-in-out

starts and ends slow and speeds up in the middle

Linear

constant rate of change

Steps

A special timing function

you give it the number of steps x

and it splits the keyframes into x equal steps then hops between them

cubic-bezier

create your unique animation

it lets give the browser a set of values to say what you want that rate of change to be when do you want to speed up and when do you want to slow down

CSS Animation #

consists of

animation: black-to-white 1s linear 1;

@keyframes black-to-white {
0% { background: #000 }
100% { background: #fff }
}

P.S: it always eats the last step so you may make your steps less by one

P.P.S: don't call your keyframes running it's a trap!!!

More Animation Properties #

fill-mode

When animations are done the element just goes to its normal state unless you use this

It has different values

animation: black-to-white 1s linear 1 backward;

play-state

from its name it's the state of the animation

it has two values

you can use paused value to run animation only on hover or maybe pause on hover!

direction

When animations goes from 0% to 100% then 0% to 100% and so on

you can change that with direction

values:

Why using animations #

smoothstate.js

dynamically load each page using AJAX

When to use transition #

Supplemental animation used for #

Animation for secondary content like alerts menu

Causal effects #

like spinners hover

Decorative animation #

doesn't add any information

Jump Cut #

from films when the camera cuts directly to a different perspective

๐ŸŽ‰๐Ÿ’…โœจ

Oh Hi๐Ÿ‘‹ You made it this far cool! ๐Ÿ™Œ If you would love to share it somewhere here you GO. Also, I would ๐Ÿ’– to hear your feedback, so feel free to ping me on Twitter. or tag me if you wish. Bye for now. Keep Learning! ๐Ÿคž

Published