Skip to main content Sidebar
On this page
Skip to table of contents

Animation

<pc-animation> 0.4.0 experimental

Animate elements declaratively with nearly 100 baked‐in presets, or roll your own with custom keyframes. These animations are powered by the Web Animations API.

To animate an element, wrap it in a <pc-animation> element 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.

<div class="animation-overview">
    <pc-animation name="bounce" duration="2000" play>
        <div class="box"></div>
    </pc-animation>
    <pc-animation name="jello" duration="2000" play>
        <div class="box"></div>
    </pc-animation>
    <pc-animation name="heartBeat" duration="2000" play>
        <div class="box"></div>
    </pc-animation>
    <pc-animation name="flip" duration="2000" play>
        <div class="box"></div>
    </pc-animation>
</div>

<style>
    .animation-overview .box {
        display: inline-block;
        inline-size: 100px;
        block-size: 100px;
        margin: 1.5rem;
        background-color: var(--pc-color-primary-fill-loud);
        border-radius: var(--pc-border-radius-l);
    }
</style>
Code Edit

The animation will only be applied to the first child element found in <pc-animation>.

Demos

Animations and easings

This demo demonstrates all of the baked‐in animations and easings. Animations are based on those found in the popular Animate.css library.

Edit

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.

Edit

Custom keyframes

Supply your own keyframes to build custom animations.

Edit

Playing animations programmatically

Animations won’t play until you add the play attribute. You can omit it initially, then apply it programmatically such as after a user interaction. In this demo, the button will animate once every time the button is clicked.

Edit

Properties

NameDescriptionReflectsDefault
nameThe name of the built‐in animation to use. For custom animations, use the keyframes prop.
Type: string
"none"
playPlays the animation. When omitted, the animation will be paused. This attribute will be automatically removed when the animation finishes or gets cancelled.
Type: boolean
false
delayThe number of milliseconds to delay the start of the animation.
Type: number
0
directionDetermines the direction of playback as well as the behaviour when reaching the end of an iteration. Learn more about the CSS animation-direction property.
Type: PlaybackDirection
"normal"
durationThe number of milliseconds each iteration of the animation takes to complete.
Type: number
1000
easingThe easing function to use for the animation. This can be an easing function name like easeInSine or a custom easing function like cubic-bezier(0.12, 0, 0.39, 0).
Type: string
"ease-in-out"
endDelay
end-delay
The number of milliseconds to delay after the active period of an animation sequence.
Type: number
0
fillSets how the animation applies styles to its target before and after its execution.
Type: FillMode
"auto"
iterationsThe number of iterations to run before the animation completes. Infinity
iterationStart
iteration-start
The offset at which to start the animation, usually between 0 (start) and 1 (end).
Type: number
0
keyframesThe keyframes to use for the animation. If this is set, the name attribute and property will be ignored.
Type: Keyframe[] | undefined
playbackRate
playback-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
1
currentTimeGets and sets the current animation time.
Type: CSSNumberish
updateComplete A read‐only promise that resolves when the component has finished updating.

Learn more about customising animations.

Slots

NameDescription
(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 <pc-animation> elements.

Learn more about using slots.

Methods

NameDescriptionArguments
cancel()Clears all keyframes 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.

Learn more about methods.

Events

NameDescriptionEvent detail
pc-cancelEmitted when the animation is cancelled.
pc-finishEmitted when the animation finishes.
pc‐startEmitted when the animation starts or restarts.

Learn more about events.

Importing

If you’re using the autoloader or the standard loader, you can skip this section. But if you’re cherry picking, you can use any of the following snippets to import this component.

CDN (script tag)CDN (import)npm (import)

To manually import this component from the CDN, copy this code snippet and paste it in your HTML.

<script type="module" src="https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.3/cdn/components/animation/animation.js"></script>

To manually import this component from the CDN, copy this code snippet and paste it in your JavaScript file.

import "https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.3/cdn/components/animation/animation.js";

To manually import this component from npm, copy this code snippet and paste it in your JavaScript file.

import "placer-toolkit/dist/components/animation/animation.js";

We’d love to hear from you. Please reach out to us with any questions or enquiries you may have.

You can contact us via e‐mail at placer.coc.reports+contact@gmail.com.

We look forward to hearing from you!

Got it!
Dangerous lands

Whoa! You’ve wandered into the dangerous lands of Placer Toolkit. Version 0 is out of date and doesn’t meet EU privacy standards, including GDPR.

Want the latest powers, security and compliance? Stick with the current version of Placer Toolkit!

Yikes! Power up!

Our site is 100 % cookie‐free! We value your privacy, which is why we don’t store any cookies or personal information related to you.

Your browser history is safe from crumbs, and your data is protected, aligning with modern privacy standards like the GDPR. Enjoy your visit without a single digital cookie in sight! 🍪🚫

View our Privacy Policy for more information.

Got it!