Animation
<pc-animation> Animiere Elemente deklarativ mit fast 100 integrierten Presets oder erstelle deine eigenen Animationen mit benutzerdefinierten Keyframes. Diese Animationen basieren auf der Web Animations API.
Um ein Element zu animieren, umschließe es mit einem <pc-animation>‐Element und lege einen Animationsnamen fest. Diese Animation startet erst, wenn du das play‐Attribut hinzufügst. In der Eigenschaften‐Tabelle findest du eine Liste aller Optionen.
<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> Diese Animation wird nur auf das erste Kindelement innerhalb von <pc-animation> angewendet.
Diese Demo zeigt alle integrierten Animationen und Easings. Die Animationen basieren auf der beliebten Animate.css‐Bibliothek.
Nutze einen Intersection Observer, um die Animation zu steuern, sobald ein Element in den Viewport eintritt oder ihn verlässt. Scrolle zum Beispiel die Box unten in den Bildschirm hinein und wieder heraus. Die Animation stoppt, wenn die Box den Viewport verlässt und startet bei jedem Eintritt neu.
Füge deine eigene Keyframes hinzu, damit du benutzerdefinierte Animationen erstellen kannst.
Animationen werden erst abgespielt, wenn du das play‐Attribut hinzufügst. Du kannst es anfangs weglassen und erst programmatisch hinzufügen, z. B. nach einer Benutzerinteraktion. In dieser Demo animiert der Button bei jedem Klick genau einmal.
| Name | Beschreibung | Reflektiert | Standard |
|---|---|---|---|
name | The name of the built‐in animation to use. For custom animations, use the keyframes prop.Typ: string |
| "none" |
play | Plays the animation. When omitted, the animation will be paused. This attribute will be automatically removed when the animation finishes or gets cancelled. Typ: boolean |
| false |
delay | The number of milliseconds to delay the start of the animation. Typ: number |
| 0 |
direction | Determines the direction of playback as well as the behaviour when reaching the end of an iteration. Learn more about the CSS animation-direction property.Typ: PlaybackDirection |
| "normal" |
duration | The number of milliseconds each iteration of the animation takes to complete. Typ: number |
| 1000 |
easing | The 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).Typ: string |
| "ease-in-out" |
endDelayend-delay | The number of milliseconds to delay after the active period of an animation sequence. Typ: number |
| 0 |
fill | Sets how the animation applies styles to its target before and after its execution. Typ: FillMode |
| "auto" |
iterations | The number of iterations to run before the animation completes. |
| Infinity |
iterationStartiteration-start | The offset at which to start the animation, usually between 0 (start) and 1 (end). Typ: number |
| 0 |
keyframes | The keyframes to use for the animation. If this is set, the name attribute and property will be ignored.Typ: Keyframe[] | undefined |
| ‐ |
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.Typ: number |
| 1 |
currentTime | Gets and sets the current animation time. Typ: CSSNumberish |
| ‐ |
updateComplete | Ein schreibgeschütztes Promise, das erfüllt ist, sobald die Komponente fertig aktualisiert wurde. | ‐ |
Erfahre mehr über Attribute und Eigenschaften.
| Name | Beschreibung |
|---|---|
| (Standard) | 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. |
Erfahre mehr über die Benutzung von Slots.
| Name | Beschreibung | Argumente |
|---|---|---|
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. | ‐ |
Erfahre mehr über Methoden.
| Name | Beschreibung | Event‐Detail |
|---|---|---|
pc-cancel | Emitted when the animation is cancelled. | ‐ |
pc-finish | Emitted when the animation finishes. | ‐ |
pc‐start | Emitted when the animation starts or restarts. | ‐ |
Erfahre mehr über Events.
Wenn du den Autoloader oder den Standard‐Loader nutzt, kannst du diesen Abschnitt überspringen. Falls du „Cherry Picking“ betreibst, kannst du die folgenden Snippets verwenden, um diese Komponente zu importieren.
Um diese Komponente manuell vom CDN zu importieren, kannst du dieses Code‐Snippet kopieren und es in dein HTML einfügen.
<script type="module" src="https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.3/cdn/components/animation/animation.js"></script> Um diese Komponente manuell vom CDN zu importieren, kannst du dieses Code‐Snippet kopieren und es in deine JavaScript‐Datei einfügen.
import "https://cdn.jsdelivr.net/npm/placer-toolkit@1.0.0-alpha.3/cdn/components/animation/animation.js"; Um diese Komponente manuell von npm zu importieren, kannst du dieses Code‐Snippet kopieren und es in deine JavaScript‐Datei einfügen.
import "placer-toolkit/dist/components/animation/animation.js";