HTML CSS examples for CSS Property:animation-direction
The animation-direction CSS property sets whether the animation should play in reverse, on alternate cycles or not.
The following table summarizes the animation-direction Property.
Item | Value |
---|---|
Default value: | normal |
Applies to: | All elements, ::before and ::after pseudo-elements |
Inherited: | No |
Animatable: | No. |
The syntax of the property is as follows:
animation-direction: normal | reverse | alternate | alternate-reverse | initial | inherit
The animation-direction property has no effect if the animation only play once.
The following table describes the values of this property.
Value | Description |
---|---|
normal | play forward in each cycle. This is default. |
reverse | play backward in each cycle. |
alternate | play forward in the first cycle, then play backward, then continues to alternate. |
alternate-reverse | play backward in the first cycle, then play forward, then continues to alternate. |
initial | Sets this property to its default value. |
inherit | take the value of its parent element animation-direction property. |
The example below shows the animation-direction property.
<!DOCTYPE html> <html lang="en"> <head> <title>Example of CSS3 animation-direction Property</title> <style type="text/css"> .box {<!-- w ww .j a v a2 s . co m--> width: 153px; height: 103px; margin: 50px; background: url("https://www.java2s.com/style/demo/Opera.png") no-repeat; position: relative; /* Chrome, Safari, Opera */ -webkit-animation-name: moveit; -webkit-animation-duration: 4s; -webkit-animation-iteration-count: 2; -webkit-animation-direction: alternate; /* Standard syntax */ animation-name: moveit; animation-duration: 4s; animation-iteration-count: 2; animation-direction: alternate; } /* Chrome, Safari, Opera */ @-webkit-keyframes moveit { from {left: 0;} to {left: 50%;} } /* Standard syntax */ @keyframes moveit { from {left: 0;} to {left: 50%;} } </style> </head> <body> <div class="box"></div> <p><strong>Note:</strong> Click the "Show Output" button to repeat the animation.</p> </body> </html>