Zum Hauptinhalt springen Seitenleiste
Zum Inhaltsverzeichnis springen

    Animation

    <pc-animation> 0.4.0 experimental

    Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

    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 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

    Eigenschaften#

    NameBeschreibungReflektiertStandard
    nameThe name of the built‐in animation to use. For custom animations, use the keyframes prop.
    Typ: 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.
    Typ: boolean
    false
    delayThe number of milliseconds to delay the start of the animation.
    Typ: 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.
    Typ: PlaybackDirection
    "normal"
    durationThe number of milliseconds each iteration of the animation takes to complete.
    Typ: 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).
    Typ: string
    "ease-in-out"
    endDelay
    end-delay
    The number of milliseconds to delay after the active period of an animation sequence.
    Typ: number
    0
    fillSets how the animation applies styles to its target before and after its execution.
    Typ: 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).
    Typ: number
    0
    keyframesThe keyframes to use for the animation. If this is set, the name attribute and property will be ignored.
    Typ: 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.
    Typ: number
    1
    currentTimeGets 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.

    Slots#

    NameBeschreibung
    (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.

    Erfahre mehr über die Benutzung von Slots.

    Methoden#

    NameBeschreibungArgumente
    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.

    Events#

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

    Erfahre mehr über Events.

    Importieren#

    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.

    CDN (Skript‐Tag)CDN (Import)npm (Import)

    Um diese Komponente manuell vom CDN zu importieren, kopiere dieses Code‐Snippet und füge es in dein HTML ein.

    <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, kopiere dieses Code‐Snippet und füge es in deine JavaScript‐Datei ein.

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

    Um diese Komponente manuell via npm zu importieren, kopiere dieses Code‐Snippet und füge es in deine JavaScript‐Datei ein.

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

    Wir würden uns freuen, von dir zu hören. Bitte kontaktiere uns bei Fragen oder Anliegen, die du hast.

    Du kannst uns per E‐Mail unter placer.coc.reports+contact@gmail.com erreichen.

    Wir freuen uns darauf, von dir zu hören!

    Alles klar!
    Gefährliche Lande

    Ui! Du bist in die gefährlichen Lande von Placer Toolkit geraten. Version 0 ist veraltet und entspricht nicht den EU‐Datenschutzstandards, einschließlich DSGVO.

    Willst du die neuesten Kräfte, Sicherheit und Compliance? Bleib bei der aktuellen Version von Placer Toolkit!

    Ups! Aufladen!