English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

CSS Reference Manual

CSS @rules

All CSS properties

CSS3 animation-play-Usage and examples of state property

CSS3 animation-play-The state property specifies whether to play the animation or pause it.

The following table summarizes the usage context and version history of this property.

Default value:running
Applies to:All elements ::before and ::after Pseudo-element
Inheritance:None
Animation can be made:No.请参见 Please see.
Animation attributes CSS3Version:
New feature of    
object    object.style.animationPlayState="paused"

animation-play-Syntax of state usage

The syntax of this attribute is as follows:

animation-play-state: paused | running | initial | inherit

The following example demonstrates how to use the animation-play-state attribute.

.box {
    width: 50px;
    height: 50px;
    background: red;
    position: relative;
    /* Chrome, Safari, Opera */
    -webkit-animation-name: moveit;
    -webkit-animation-duration: 2s;
    -webkit-animation-play-state: paused;
    
    animation-name: moveit;
    animation-duration: 2s;
    animation-play-state: paused;
}
 
/* Chrome, Safari, Opera */
@-webkit-keyframes moveit {
    from {left: 0;}
    to {left: 50%;}
}
 
@keyframes moveit {
    from {left: 0;}
    to {left: 50%;}
}
Test and see‹/›

Attribute value

The following table describes the value of this attribute.

ValueDescription
pausedSpecify that the animation is currently paused.
runningSpecify that the animation is currently running. This is the default value.
initialSet this property to its default value.
inheritIf specified, the associated element adopts its parent element's animation-play-The calculated value of the state attribute.

Note:The animation can be-play-The state attribute can be used in combination with JavaScript to pause the animation at the middle of the loop.

Browser compatibility

animation-play-Browser compatibility of the state attribute, all mainstream browsers support this attribute.

  • Firefox 5+ -moz-,15 +

  • Google Chrome 4+ -webkit-

  • Internet Explorer 10+

  • Apple Safari 4+ -webkit-

  • Opera 12+ -o-,15+ -webkit-

For further reading

Please refer to the following tutorial:CSS3Animation.

Related attributes and rules:animation-name,animation-duration,animation-timing-function,animation-delay,animation-iteration-count,animation-direction,animation-fill-mode,animation-play-state,@keyframes.