Animation

View Source

NOTE: Introduced feature in v0.6.0.

Animation is used to apply infinitely repeating animations on a containing element that will also include its children. Typically used for situations like alerting users to new E-Mail in their inbox, etc...

<script>
    import {
        Animation,
        Button,
        Dot,
        Position,
    } from "@kahi-ui/framework";
</script>

<Button palette="accent">
    Inbox
    <Position variation="indicator">
        <Animation animation="ping">
            <Dot palette="negative" />
        </Animation>
    </Position>
</Button>

Imports

<script>
    import {Animation} from "@kahi-ui/framework";
</script>

Delay

Based on the animaton duration properties in the currently loaded theme. You can use a multiplier percentage decimal to delay it via the delay property.

<script>
    import {Animation, Dot} from "@kahi-ui/framework";
</script>

<Animation animation="bounce">
    <Dot palette="accent" />
</Animation>

<Animation animation="bounce" delay={-0.75}>
    <Dot palette="accent" />
</Animation>

<Animation animation="bounce" delay={-0.5}>
    <Dot palette="accent" />
</Animation>

<Animation animation="bounce" delay={-0.25}>
    <Dot palette="accent" />
</Animation>

Duration

Based on the animaton duration properties in the currently loaded theme. You can use a multiplier percentage decimal to increase / shorten the animation duration via the duration property.

<script>
    import {Animation, Dot} from "@kahi-ui/framework";
</script>

<Animation animation="bounce" duration={0.25}>
    <Dot palette="accent" />
</Animation>

<Animation animation="bounce">
    <Dot palette="accent" />
</Animation>

<Animation animation="bounce" duration={1.75}>
    <Dot palette="accent" />
</Animation>

<Animation animation="bounce" duration={2.5}>
    <Dot palette="accent" />
</Animation>

Iterations

You can control how many times the animation repeats before stopping via the iterations property.

<script>
    import {
        Animation,
        Dot,
        NumberInput,
    } from "@kahi-ui/framework";

    let iterations = 0;
</script>

<NumberInput bind:value={iterations} />

<!--
    NOTE: CSS keeps the current iteration count if you only change
    the `animation-iteration-count` property. So we're using `{#key}`
    here to reset the internal counter
-->

{#key iterations}
    <Animation animation="bounce" {iterations}>
        <Dot palette="accent" />
    </Animation>
{/key}

Variation

You can control whether the animation is playing or paused via the variation property.

<script>
    import {
        Animation,
        Button,
        Dot,
    } from "@kahi-ui/framework";

    let variation = undefined;
</script>

<Button
    on:click={() =>
        (variation =
            variation === "pause" ? "play" : "pause")}
>
    Toggle Variation
</Button>

<Animation animation="bounce" {variation}>
    <Dot palette="accent" />
</Animation>

Elements

You can change the HTML tag rendered to DOM via the is property.

<script>
    import {
        Animation,
        Box,
        Button,
        Stack,
        Text,
    } from "@kahi-ui/framework";
</script>

<Stack.Container
    spacing="medium"
    orientation="horizontal"
    variation="wrap"
>
    <div>
        <Text is="strong">DIV / BLOCK</Text>

        <Animation is="div" animation="bounce">
            <Box palette="inverse" padding="medium">
                I booouunce, I bounce so far
                awaaaaaay~!
            </Box>
        </Animation>
    </div>

    <div>
        <Text is="strong">SPAN / INLINE</Text>

        <Animation is="span" animation="bounce">
            <Box palette="inverse" padding="medium">
                I booouunce, I bounce so far
                awaaaaaay~!
            </Box>
        </Animation>
    </div>
</Stack.Container>

Bounce

You can have content "bounce" up and down via the animation property.

<script>
    import {Animation, Dot} from "@kahi-ui/framework";
</script>

<Animation animation="bounce">
    <Dot palette="accent" />
</Animation>

Ping

You can have content "explode" outwards, fading as the animation is playing via the animation property.

<script>
    import {Animation, Dot} from "@kahi-ui/framework";
</script>

<Animation animation="ping">
    <Dot palette="accent" />
</Animation>

Pulse

You can have content "glow" bright and dim via the animation property.

<script>
    import {Animation, Dot} from "@kahi-ui/framework";
</script>

<Animation animation="pulse">
    <Dot palette="accent" />
</Animation>

Properties

Animation

Name Description Types
is Alters the HTML tag rendered to the DOM.
div (DEFAULT) span
animation Selects the animation to be ran on the containing Animation element.
bounce ping pulse
delay Sets how long after a variation property change in a percentage range (e.g. 0.2) that the animation should start.
number string
duration Sets a percentage range (e.g. 0.2, 2.5) multiplier on the current theme's duration on how long should the animation play.
number string
iterations Sets how many times the animation should be played until it stops.
number string
variation Controls if the selected animation is playing or paused.
pause play (DEFAULT)

Events

Animation

Name Description Types
animationend Fires whenever the Animation animation ends.
AnimationEvent
animationstart Fires whenever the Animation animation starts.
AnimationEvent

Slots

Animation

Name Description Types
default Default unnamed slot.
{}