WEB DEVELOPER SITE
HTMLCSSJAVASCRIPTSQLPHPBOOTSTRAPJQUERYANGULARXML
 

CSS3 Animations


CSS3 Animations

CSS3 livelinesss permits movement of most HTML components without utilizing JavaScript or Flash!

CSS3
Animation

Browser Support for Animations

The numbers in the table determine the main program form that completely bolsters the property.

Numbers pursued by - webkit-, - moz-, or - o-indicate the principal form that worked with a prefix.

Property
@keyframes 43.0
4.0 - webkit-
12.0 10.0 16.0
5.0 - moz-
9.0
4.0 - webkit-
30.0
15.0 - webkit-
12.0 - o-
animation 43.0
4.0 - webkit-
12.0 10.0 16.0
5.0 - moz-
9.0
4.0 - webkit-
30.0
15.0 - webkit-
12.0 - o-

What are CSS3 Animations?

An activity lets a component bit by bit change from one style to another.

You can change the same number of CSS properties you need, the same number of times you want.

To use CSS3 liveliness, you should initially determine some keyframes for the animation.

Keyframes hold what styles the component will have at certain times.


The @keyframes Rule

When you determine CSS styles inside the @keyframes rule, the activity will bit by bit change from the present style to the new style at certain times.

To motivate a movement to work, you should tie the liveliness to an element.

The following model ties the "example" liveliness to the <div> component. The movement will goes on for 4 seconds, and it will continuously change the foundation shade of the <div> component from "hotpink" to "darkblue":

Example

/* The movement code */
@keyframes model {
    from {background-shading: hotpink;}
    to {background-shading: darkblue;}
}

/* The component to apply the movement to */
div {
    width: 100px;
    stature: 100px;
    foundation shading: hotpink;
    movement name: example;
    activity span: 4s;
}
Try it yourself »

Note: If the animation-duration property isn't indicated, the activity will have no impact, in light of the fact that the default esteem is 0. 

In the precedent above we have determined when the style will change by utilizing the catchphrases "from" and "to" (which speaks to 0% (begin) and 100% (complete)).

It is additionally conceivable to utilize percent. By utilizing percent, you can include the same number of style changes as you like.

The following precedent will change the foundation shade of the <div> component when the movement is 25% finished, half total, and again when the liveliness is 100% complete:

Example

/* The movement code */
@keyframes precedent {
    0%   {background-shading: hotpink;}
    25%  {background-shading: darkblue;}
    50%  {background-shading: blue;}
    100% {background-shading: green;}
}

/* The component to apply the movement to */
div {
    width: 100px;
    stature: 100px;
    foundation shading: hotpink;
    movement name: example;
    movement length: 4s;
}
Try it yourself »

The following model will change both the foundation shading and the situation of the <div> component when the movement is 25% finished, half total, and again when the liveliness is 100% complete:

Example

/* The liveliness code */
@keyframes model {
    0%   {background-shading: hotpink; left:0px; top:0px;}
    25%  {background-shading: darkblue; left:200px; top:0px;}
    50%  {background-shading: blue; left:200px; top:200px;}
    75%  {background-shading: green; left:0px; top:200px;}
    100% {background-shading: hotpink; left:0px; top:0px;}
}

/* The component to apply the liveliness to */
div {
    width: 100px;
    tallness: 100px;
    position: relative;
    foundation shading: hotpink;
    liveliness name: example;
    liveliness term: 4s;
}
Try it yourself »

Delay an Animation

The animation-delay property determines a deferral for the beginning of an animation.

The following precedent has a 2 seconds postponement before beginning the animation:

Example

div {
    width: 100px;
    tallness: 100px;
    position: relative;
    foundation shading: hotpink;
    liveliness name: example;
    liveliness term: 4s;
    movement delay: 2s;
}
Try it yourself »

Set How Many Times an Animation Should Run

The animation-cycle count property indicates the occasions a movement ought to run.

The following model will run the liveliness multiple times previously it stops:

Example

div {
    width: 100px;
    tallness: 100px;
    position: relative;
    foundation shading: hotpink;
    liveliness name: example;
    liveliness term: 4s;
    movement cycle tally: 3;
}
Try it yourself »

The following precedent uses the esteem "infinite" to make the movement proceed for ever:

Example

div {
    width: 100px;
    stature: 100px;
    position: relative;
    foundation shading: hotpink;
    movement name: example;
    movement span: 4s;
    activity emphasis check: infinite;
}
Try it yourself »

Run Animation in Reverse Direction or Alternate Cycles

The animation-direction property is utilized to give a liveliness a chance to keep running backward heading or interchange cycles.

The following precedent will run the activity in invert direction:

Example

div {
    width: 100px;
    stature: 100px;
    position: relative;
    foundation shading: hotpink;
    movement name: example;
    movement length: 4s;
    liveliness emphasis tally: 3;
    activity bearing: reverse;
}
Try it yourself »

The following model uses the esteem "alternate" to make the liveliness first kept running forward, at that point in reverse, at that point forward:

Example

div {
    width: 100px;
    tallness: 100px;
    position: relative;
    foundation shading: hotpink;
    liveliness name: example;
    liveliness span: 4s;
    movement emphasis tally: 3;
    activity heading: alternate;
}
Try it yourself »

Specify the Speed Curve of the Animation

The animation-timing-function property indicates the speed bend of the animation.

The movement timing-work property can have the accompanying values:

  • ease - determines a movement with a moderate begin, at that point quick, at that point end gradually (this is default)
  • linear - determines a movement with a similar speed from begin to end
  • ease-in - determines a movement with a moderate start
  • ease-out - determines a movement with a moderate end
  • ease-in-out - determines a movement with a moderate begin and end
  • cubic-bezier(n,n,n,n) - gives you a chance to characterize your own qualities in a cubic-bezier function

The following precedent demonstrates the a portion of the distinctive speed bends that can be used:

Example

#div1 {animation-timing-work: linear;}
#div2 {animation-timing-work: ease;}
#div3 {animation-timing-work: ease-in;}
#div4 {animation-timing-work: ease-out;}
#div5 {animation-timing-work: ease-in-out;}
Try it yourself »

Animation Shorthand Property

The model underneath utilizations six of the activity properties:

Example

div {
    movement name: example;
    movement span: 5s;
    movement timing-work: linear;
    liveliness delay: 2s;
    liveliness emphasis tally: infinite;
    liveliness bearing: alternate;
}
Try it yourself »

The same liveliness impact as above can be accomplished by utilizing the shorthand animation property:

Example

div {
    liveliness: precedent 5s direct 2s interminable alternate;
}
Try it yourself »