CSS Animations
I want to learn more about CSS animations so I am either going to read the MDN docs or find another resource to learn more about them.
References
Related
- Composite Operation
- In CSS, the value of a property in a CSS rule is the underlying value of that property, and the value of that same property in a keyframe is its effect value.
- Composite operation is the specific operation that is used to combine an effect value with an underlying value to produce the final keyframe effect value. There are three types of composite operations:
- replace: The effect value replaces the underlying value. The final effect value in this case is the original effect value itself.
- add: The effect value is added to the underlying value.
- accumulate: The effect value is combined with the underlying value.
- Keyframe
- The
@keyframes
CSS at-rule controls the intermediate steps in a CSS animation sequence by defining styles for keyframes (or waypoints) along the animation sequence. This gives more control over the intermediate steps of the animation sequence than transitions. You can list the keyframes percentages in any order; they will be handled in the order they should occur. If multiple keyframe sets exist for a given name, the last one encountered by the parser is used. Properties that aren't specified in every keyframe are interpolated if possible - properties that can't be interpolated are dropped from the animation. Declarations in a keyframe qualified with!important
are ignored.
- The
@keyframes slide-in {
from {
transform: translateX(0%);
}
to {
transform: translateX(100%);
}
}
- Values:
-
from
- A starting offset of
0%
- A starting offset of
to
- An ending offset of
100%
- An ending offset of
<percentage>
- A percentage of the time through the animation sequence at which the specified keyframe should occur.
<timeline-range-name> <percentage>
- A percentage of the time through the specified
animation-range
at which the specified keyframe should occur.
- A percentage of the time through the specified
-
- At-rules
- At-rules are CSS statements that instruct CSS how to behave. They begin with an at sign,
@
, followed by an identifier, and include everything up to the next semicolon,;
, or the next CSS block, whichever comes first.
- At-rules are CSS statements that instruct CSS how to behave. They begin with an at sign,
- CSS Declaration Block
- Declarations re grouped in blocks, that is in a structure delimited by an opening brace,
{
, and a closing one,}
. Blocks sometimes can be nested, so opening and closing braces must be matched. Such blocks are naturally considered declaration blocks and declarations inside them are separated by a semicolon,;
.
- Declarations re grouped in blocks, that is in a structure delimited by an opening brace,
Notes
The CSS animations module lets you animate the values of CSS properties, such as background-position and transform, over time and by using keyframes. Each keyframe describes how the animated element should render at a given time during the animation sequence. You can use the properties in the animations module to control the duration, number of repetitions, delayed start, and other aspects of an animation.
Properties
animation
shorthand
/* @keyframes duration | easing-function | delay |
iteration-count | direction | fill-mode | play-state | name */
animation: 3s ease-in 1s 2 reverse both paused slide-in;
/* @keyframes duration | easing-function | delay | name */
animation: 3s linear 1s slide-in;
/* two animations */
animation: 3s linear slide-in, 3s ease-out 5s slide-out;
animation-composition
- Species the composite operation to use when multiple animations affect the same property simultaneously.
animation-delay
- Specifies the amount of time to wait from applying the animation to an element before beginning to perform the animation. The animation can start later, immediately from its beginning, or immediately and partway through the animation.
animation-direction
- Property sets whether an animation should play forward, backward, or alternate back and forth between playing the sequence forward and backward.
animation-duration
- Sets the length of time that an animation takes to complete one cycle.
animation-fill-mode
- Property sets how a CSS animation applies styles to its target before and after its execution.
animation-iteration-count
- Property sets the number of times an animation sequence should play before stopping.
animation-name
- Specifies the name of one or more
@keyframes
at-rules that describe the animation to apply to an element. Multiple@key-frame
at-rules are specified as comma-separated list of names. If the specified name does not match any@key-frame
at-rule, no properties are animated.
- Specifies the name of one or more
animation-play-state
- The property sets whether an animation is running or paused.
animation-timing-function
- Property sets how an animation progresses through the duration of each cycle.
At-Rules
@keyframes
- See above.
Events
animationstart
- Event fired when a CSS Animation has started. If there is an
animation-delay
, this event will fire once the delay period has expired. A negative value will cause the event to fire with anelapsedTime
equal to the absolute value of the delay.
- Event fired when a CSS Animation has started. If there is an
animationend
- The
animationend
event is fired when a CSS Animation has completed. If the animation aborts before reaching completion, such as if the element is removed from the DOM or the animation is removed from the element, theanimationend
event is not fired.
- The
animationcancel
- The
nimationcancel
event is fired when a CSS Animation unexpectedly aborts. In other words, any time it stops running without sending ananimationend
event. This might happen when theanimation-name
is changed such that the animation is removed, or when the animation node is hidden using CSS.
- The
animationiteration
- This event is fired when an iteration of a CSS Animation ends, and another one begins. This event does not occur at the same time as the
animationend
event, and therefore does not occur for animations with ananimation-iteration-count
of one.
- This event is fired when an iteration of a CSS Animation ends, and another one begins. This event does not occur at the same time as the
There are three key advantages to CSS animations over traditional script-driven animation techniques:
- They're easy to use for simple animations; you can create them without even having to know JavaScript
- The animations run well, even under moderate system load.
- Letting the browser control the animation sequence lets the browser optimize performance and efficiency by, for example, reducing the update frequency of animations running in tabs that aren't currently visible.
Comments
You have to be logged in to add a comment
Comments are currently ranked/sorted according to the this daily reading article. Since comments do not have upvotes and downvotes, but only likes, 1 nested comment on a comment is set to equal 20 upvotes, 1 like is set to equal 1 upvote, and the number of downvotes is calculated to be the number of views divided by 10.
ranking algorithm as explained inUser Comments
There are currently no comments for this article.