English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
CSS animation-The direction attribute specifies whether the animation should play in reverse in an alternating loop.
The following table summarizes the usage context and version history of this attribute.
Default value: | normal |
---|---|
Applies to: | All elements ::before and ::after Pseudo-element |
Inheritance: | None |
Animatable: | No.See also Animation properties. |
Version: | CSS3New feature of |
JavaScript syntax: | JavaScript syntax: object.style.animationDirection="reverse" |
The syntax of this attribute is as follows:
animation-direction: normal | reverse | alternate | alternate-reverse | initial | inherit
The following example demonstrates how to use animation-direction attribute.
.box { width: 50px; height: 50px; background: red; position: relative; /* Chrome, Safari, Opera */ -webkit-animation-name: moveit; -webkit-animation-duration: 4s; -webkit-animation-iteration-count: 2; -webkit-animation-direction: alternate; 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%;} } @keyframes moveit { from {left: 0;} to {left: 50%;} }Test and see‹/›
Note:If the animation is set to play only once, then animation-The direction attribute is invalid, please seeanimation-iteration-countAttribute.
The following table describes the values of this attribute.
Value | Description |
---|---|
normal | The animation should play in each cycle. This is the default value. |
reverse | The animation should play backward in each loop. |
alternate | The animation plays forward in the first loop, then backward, and then continues to alternate. |
alternate-reverse | The animation plays backward in the first loop, then forward, and then continues to alternate. |
initial | Set this property to its default value. |
inherit | If specified, the associated elements use the computed value of the animation of their parent element-direction. |
animation-Browser compatibility of the direction attribute, all major browsers support this attribute.
|
Please refer to the following tutorials:CSS3Animation.
Related attributes and rules:animation,animation-name,animation-delay,animation-timing-function,animation-iteration-count,animation-direction,animation-fill-mode,animation-play-state,@keyframes.