FOLLOW US ON TWITTER



FOLLOW US



img/blogimg/css3.jpg


@coder 933

CSS3 ANIMATIONS


2021-11-16 23:46 · 8 min read

The CSS3 animation property allows us to use multiple CSS Style properties at a specific interval. We use keyframes for applying animation on an HTML element.


How to use animation property on your web page?

Animation property gives an attractive look to your website. We can use multiple animations at a time on an HTML element.

  • Here we will discuss

    • @keyframes
    • animation-name
    • animation-delay
    • animation-duration
    • animation-iteration-count
    • animation-timing-function
    • animation-direction
    • animation-fill-mode
    • animation

These values allow us to add different animation effects on our web page.

<style>
.tdb-block{
padding:5px 10px;
width:100px;
height:50px;
background-color:black;
animation:animation-name 1s;
}
/* animation @keyframe rule */
@keyframes animation-name {
from {margin-left: 0px}
to {margin-left: 250px;}
}
</style>

<div class="tdb-block">tdb-block</div>

 

Animation @keyframes rules

First, we have to specify some keyframes for the animations. Keyframes allow holding CSS styles for a specific duration.

 

<style>
/* animation @keyframe rule */
@keyframes example {
from {property: value}
to {property: value;}
}
</style>


We can also specify multiple CSS3 properties during the animation

 

<style>
/* multiple animation effects */
@keyframes animation-name {
0% {margin-left: 0px;}
20% {margin-left: 100px;}
30% {margin-left: 50px;}
50% {margin-left: 200px;}
80% {margin-left: 100px;}
100% {margin-left: 250px;}
}
</style>
<head>
<style>
.tdb-block{
padding:5px 10px;
width:100px;
height:50px;
background-color:black;
animation:animation-name 1s;
}
/* animation @keyframe rule */
@keyframes animation-name {
0% {margin-left: 0px;}
20% {margin-left: 100px;}
30% {margin-left: 50px;}
50% {margin-left: 200px;}
80% {margin-left: 100px;}
100% {margin-left: 250px;}
}
</style>
</head>

<body>
<div class="tdb-block">tdb-block</div>
</body>

 

Other Animation Properties

We can also use other values used in animation.

 

  • animation-delay
    CSS3 animation-delay property is used to add a delay for the start of an animation.
<style>
/* animation delay*/
.tdb-animation{
animation-name: tdb-animation;
animation-duration: 4s;
animation-delay: 5s;
}
/*now the animation will start after 5 seconds */
</style>
  • animation-iteration-count propety;
    CSS3 animation-iteration-count property is used to specify how many times an animation should run.
<style>
/*animation-iteration-count*/
.tdb-animation{
animation-iteration-count: 5 /*or infinite*/;
}
/*the animation will run for 5 times */
</style>
  • animation timing function;
    CSS3 animation-iteration-count property is used to specify how many times an animation should run.

SYNTAX
animation-timing-function: ease-in | ease-out | linear | ease | cubic-bezier(n,n,n,n) | step-start | step-end | ease-in-out | steps(int,start | end) | initial | inherit;

 

<style>
/*animation timing function*/
.tdb-animation{
animation-timing-function: linear;
}
</style>
<!DOCTYPE html>
<html>
<head>
<style>
.tdb-block
{
padding:5px 10px;
width:100px;
height:50px;
background-color:black;
animation:animation-name 1s;
animation-delay: 1s;
animation-iteration-count: 5;
animation-timing-function: linear;
}

/* animation @keyframe rule */
@keyframes animation-name
{
0% {
margin-left: 0px;
}
20% {
margin-left: 100px;
}
30% {
margin-left: 50px;
}
50% {
margin-left: 200px;
}
80% {
margin-left: 100px;
}
100% {
margin-left: 250px;
}
}
</style>
</head>

<body>
<div class="tdb-block">tdb-block</div>
</body>
<html>
  • animation-direction
    CSS3 animation-direction property is used to specify the direction of the animation.

Syntax
animation-direction: normal | reverse | alternate | alternate-reverse;

<style>
/* animation delay*/
.tdb-animation{
animation-name: tdb-animation;
animation-duration: 4s;
animation-direction: normal | reverse | alternate
| alternate-reverse;
}
</style>
  • animation fill-mode
    CSS3 animation-fill-mode property is used to specify the final position of an animated HTML element. It has 3 important values (forwards, backward, both).

Syntax
animation-fill-mode: none | forwards | backwards | both | initial | inherit;

<style>
/*animation-iteration-count*/
.tdb-animation{
animation-iteration-count: 5;
animation-fill-mode: backward;
}
</style>
  • animation shorthand property
    CSS3 animation is a shorthand animation property in which we can specify all CSS properties in one property.

SYNTAX
animation: animation-name duration timing-function delay iteration-count direction fill-mode play-state;

 

<style>
/*animation timing function*/
.tdb-animation{
animation: tdb-animation 10s linear 5s 3 forward;
}
</style>
<!DOCTYPE html>
<html>
<head>
<style>
.tdb-block
{
padding:5px 10px;
width:100px;
height:50px;
background-color:black;
animation:animation-name 1s;
animation-direction: normal;
animation-fill-mode: backward;
animation-delay: 1s;
animation-iteration-count: 5;
animation-timing-function: linear;
animation-direction: normal;
animation-fill-mode: backward;
}
.animation{
animation: tdb-animation 5s linear;
padding:5px 10px;
width:100px;
height:50px;
background-color:orange;
}

@keyframes tdb-animation
{
0% {
margin-left: 0px;}
100% {
margin-left: 250px;}
}

@keyframes animation-name
{
0% {
margin-left: 0px;}
100% {
margin-left: 250px;}
}
</style>
</head>

<body>
<div class="tdb-block">tdb-block</div></br>
<div class="animation">tdb-block</div>
</body>
<html>


 

TAGS:






POST COMMENTS
No Comment

Please login to post comment




POPULAR POSTS

best free web hosting services...
what is new in miui 11?...
free website ssl security using cloudfla...
do you want to make money online?...
CSS3 @IMPORT RULES...
What is HTML Anchor Tag and Hyperlinks?...
CSS3 RESPONSIVE UI...
How to host a web page in 10 minutes....
Tables HTML...
CSS3 FUNCTIONS...
How to use CSS3 Overflow Property?...
CSS3 FILTERS...


RECENT COMMENTS

2022-03-05 11:05
By coder on XAMPP - MySQL shutdown unexpectedly | How to fix MySQL crash unexpectedly
2021-10-12 12:34
By abnongoke on do you want to make money online?
2021-10-12 12:34
By abnongoke on how to get a free website domain name?
2021-10-12 12:34
By solar panel for shed on what is new in miui 11?
2021-10-12 12:34
By solar panel for shed on best free web hosting services
2021-10-12 12:34
By amos tanui on free website ssl security using cloudflare


SOCIAL SHARE



FOLLOW US ON TWITTER



FOLLOW US ON FACEBOOK



FOLLOW US







Recent Blogs



Contact Us

Subscribe Our News-Letter



Kashipur, 244713
Uttarakhand, India



© blog.theprodevelopers.com 2024. All Rights Reserved. Powered by Pro Developer