reading-notes


Project maintained by Razan-am Hosted on GitHub Pages — Theme by mattgraham

CSS Transforms, Transitions, and Animations

Transforms

Transform Syntax

Example:

div {

transform: scale(1.5);

}

2D Transforms

Example:

.box-1 {

transform: rotate(20deg);

}

.box-2 {

transform: rotate(-55deg);

}

Example:

.box-1 { transform: scale(.75);

}

.box-2 {

transform: scale(1.25);`

}

It can also write for each axis as : .box-1 {transform: scaleX(.5);}// .box-2 {transform: scaleY(1.15);}// .box-3 {transform: scale(.5, 1.15);}

Example:

box-1 {

transform: translateX(-10px);

}

.box-2 {

transform: translateY(25%);

}

.box-3 {

transform: translate(-10px, 25%);

}

Example:

.box-1 {

transform: skewX(5deg);

}

.box-2 {

transform: skewY(-20deg);

}

.box-3 {

transform: skew(5deg, -20deg);

}

Example:

.box-1 {

transform: rotate(25deg) scale(.75);

}

.box-2 {

transform: skew(10deg, 20deg) translateX(20px);

}

Example:

box-1 {

transform: rotate(15deg);

transform-origin: 0 0;

}

.box-2 {

transform: scale(.5);

transform-origin: 100% 100%;

}

.box-3 {

transform: skewX(20deg);

transform-origin: top left;

}

.box-4 {

transform: scale(.75) translate(-10px, -10px);

transform-origin: 20px 50px;

}

Example:

.box {

transform: perspective(200px) rotateX(45deg);

}

Transitions

Example:

.box {

background: #2db34a;

transition-property: background;

transition-duration: 1s;

transition-timing-function: linear;

}

.box:hover {

background: #ff7b29;

}

Example:

transition-property: background, border-radius;

the more popular transitional properties include the following: <background-color,background-position,border-color,border-width,border-spacing,bottom,clip,color,crop,font-size,font-weight,height,left,letter-spacing,line-height,margin,max-height,max-width,min-height,min-width,opacity,outline-coloro,utline-offset,outline-width,padding,right,text-indent,text-shadow,top,vertical-align,visibility,width,word-spacing,z-index.>

Example:

transition-duration: .2s, 1s;

Example:

transition-timing-function: linear, ease-in;

A few of the more popular keyword values for the transition-timing-function property:

  • linear, ease-in, ease-out, and ease-in-out.

Example:

.box {

background: #2db34a;

border-radius: 6px

transition-property: background, border-radius;

transition-duration: .2s, 1s;

transition-timing-function: linear, ease-in;

transition-delay: 0s, 1s;

}

.box:hover {

background: #ff7b29;

border-radius: 50%;

}

Example:

.box {

background: #2db34a;

border-radius: 6px;

transition: background .2s linear, border-radius 1s ease-in 1s;

}

.box:hover {

color: #ff7b29;

border-radius: 50%;

}

Animations

Example:

@keyframes slide {

0% {

left: 0;

top: 0;

}

50% {

left: 244px;

top: 100px;

}

100% {

left: 488px;

top: 0;

}

}

it’s applied to the element in which the animation is to be applied to.

Example:

.stage:hover .ball {

animation-name: slide;

}

Example:

.stage:hover .ball {

animation-name: slide;

animation-duration: 2s;

animation-timing-function: ease-in-out;

animation-delay: .5s;

}

Using an integer will repeat the animation as many times as specified, while the infinite keyword will repeat the animation indefinitely in a never ending fashion.

Example:

.stage:hover .ball {

animation-name: slide;

animation-duration: 2s;

animation-timing-function: ease-in-out;

animation-delay: .5s;

animation-iteration-count: infinite;

}

Values for the animation-direction property include normal, reverse, alternate, and alternate-reverse.

Example:

.stage:hover .ball {

animation-name: slide;

animation-duration: 2s;

animation-timing-function: ease-in-out;

animation-delay: .5s;

animation-iteration-count: infinite;

animation-direction: alternate;

}

Example:

.stage:active .ball {

animation-play-state: paused;

}

The animation-fill-mode property accepts four keyword values, including none, forwards, backwards, and both.

Example:

.stage:hover .ball {

animation-name: slide;

animation-duration: 2s;

animation-timing-function: ease-in-out;

animation-delay: .5s;

animation-fill-mode: forwards;

}

Example:

.stage:hover .ball {

animation: slide 2s ease-in-out .5s infinite alternate;

}

References:

@Shay Howe /Transforms, Transitions, and Animations