Giter VIP home page Giter VIP logo

svanim's Introduction

Svanim

Animation utillities for svelte/motion stores.

Installation

npm i svanim

Svelte/motion stores are powerful ways to tween values over time. This is a tiny lib that allows you to pass in an array of store transormations and play them as keyframes or staggered. It will simply loop over the array and play them using setTimeout();

It returns a play() function that allows you to manually (re)start the timeline and a cancel() function that stops the animation after the current transform is complete.

Usage

Keyframes:

<script>
  import { keyframe } from 'svanim'
  import { tweened } from 'svelte/motion'

  let width = tweened(100)

  let frames = [{
      { s: width, to: 100, time: 0 }
      { s: width, to: 1000, time: 1000 }
      { s: width, to: 500, time: 3000 }
  }]

  let tl = timeline(frames, { autoplay: false, direction: 'alternate', loop: true });
</script>

<div style="width: {$width}px">I will be changing my width.</div>

<button on:click="{" tl.play }>Start looping through the keyframes</button>

Staggered:

<script>
  import { stagger } from 'svanim'
  import { tweened } from 'svelte/motion'

  let one = tweened(100)
  let two = tweened(100)
  let three = tweened(100)

  let frames = [{
      { s: one, to: 500 }
      { s: two, to: 500 }
      { s: three, to: 500 }
  }]

  let st = stagger(frames, { autoplay: false, delay: 250 })
</script>

<div style="width: {$one}px">I am first</div>

<div style="width: {$two}px">I am second</div>

<div style="width: {$three}px">I am third</div>

<button on:click="{" st.play }>Start staggered animation</button>

svanim's People

Contributors

nikolai-cc avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.