Animation
Animate elements declaratively with nearly 100 baked-in presets, or roll your own with custom keyframes. Powered by the Web Animations API.
To animate an element, wrap it in <wa-animation> and set an animation name. The animation will not start until you add the play attribute. Refer to the properties table for a list of all animation options.
The animation will only be applied to the first child element found in <wa-animation>.
Examples
Animations & Easings
This example demonstrates all of the baked-in animations and easings. Animations are based on those found in the popular Animate.css library.
Using Intersection Observer
Use an Intersection Observer to control the animation when an element enters or exits the viewport. For example, scroll the box below in and out of your screen. The animation stops when the box exits the viewport and restarts each time it enters the viewport.
Custom Keyframe Formats
Supply your own keyframe formats to build custom animations.
Playing Animations on Demand
Animations won't play until you apply the play attribute. You can omit it initially, then apply it on demand such as after a user interaction. In this example, the button will animate once every time the button is clicked.
Importing
If you're using the autoloader or a hosted project, components load on demand — no manual import needed. To cherry-pick a component manually, use one of the following snippets.
Import this component directly from the CDN:
import 'https://ka-f.webawesome.com/webawesome@0.17.0/components/animation/animation.js';
After installing Web Awesome via npm, import this component:
import '@awesome.me/webawesome/dist/components/animation/animation.js';
If you're self-hosting Web Awesome, import this component from your server:
import './webawesome/dist/components/animation/animation.js';
To import this component for React 18 or below, use the following code:
import WaAnimation from '@awesome.me/webawesome/dist/react/animation/index.js';
Slots
Learn more about using slots.
| Name | Description |
|---|---|
| (default) | The element to animate. Avoid slotting in more than one element, as subsequent ones will be ignored. To animate multiple elements, either wrap them in a single container or use multiple <wa-animation> elements. |
Attributes & Properties
Learn more about attributes and properties.
| Name | Description | Reflects |
|---|---|---|
currentTime |
Gets and sets the current animation time.
Type
CSSNumberish
|
|
delaydelay |
The number of milliseconds to delay the start of the animation.
Type
number
Default
0
|
|
directiondirection |
Determines the direction of playback as well as the behavior when reaching the end of an iteration.
Learn more
Type
PlaybackDirection
Default
'normal'
|
|
durationduration |
The number of milliseconds each iteration of the animation takes to complete.
Type
number
Default
1000
|
|
easingeasing |
The easing function to use for the animation. This can be a Web Awesome easing function or a custom easing function
such as
cubic-bezier(0, 1, .76, 1.14).
Type
string
Default
'linear'
|
|
endDelayend-delay |
The number of milliseconds to delay after the active period of an animation sequence.
Type
number
Default
0
|
|
fillfill |
Sets how the animation applies styles to its target before and after its execution.
Type
FillMode
Default
'auto'
|
|
iterationsiterations |
The number of iterations to run before the animation completes. Defaults to
Infinity, which loops.
Type
number
Default
Infinity
|
|
iterationStartiteration-start |
The offset at which to start the animation, usually between 0 (start) and 1 (end).
Type
number
Default
0
|
|
keyframes |
The keyframes to use for the animation. If this is set,
name will be ignored.
Type
Keyframe[] | undefined
|
|
namename |
The name of the built-in animation to use. For custom animations, use the
keyframes prop.
Type
string
Default
'none'
|
|
playplay |
Plays the animation. When omitted, the animation will be paused. This attribute will be automatically removed when
the animation finishes or gets canceled.
Type
boolean
Default
false
|
|
playbackRateplayback-rate |
Sets the animation's playback rate. The default is
1, which plays the animation at a normal speed. Setting this
to 2, for example, will double the animation's speed. A negative value can be used to reverse the animation. This
value can be changed without causing the animation to restart.
Type
number
Default
1
|
Methods
Learn more about methods.
| Name | Description | Arguments |
|---|---|---|
cancel() |
Clears all keyframe effects caused by this animation and aborts its playback. | |
finish() |
Sets the playback time to the end of the animation corresponding to the current playback direction. |
Events
Learn more about events.
| Name | Description |
|---|---|
wa-cancel |
Emitted when the animation is canceled. |
wa-finish |
Emitted when the animation finishes. |
wa-start |
Emitted when the animation starts or restarts. |
SSR
Learn more about Server-Side Rendering (SSR).
<wa-animation> renders during SSR without causing layout shift, but won't play its animation until the component hydrates on the client. Playback is driven by the Web Animations API, which is only available in the browser.