Have ideas to improve npm?Join in the discussion! »

    animation-frame-delta
    TypeScript icon, indicating that this package has built-in type declarations

    2.7.7 • Public • Published

    Animation frame delta

    Example

    Register a animation loop like so

    import animFrame from "animation-frame-delta"
     
    animFrame((delta, timestamp, absoluteDelta) => {
      console.log(delta)          // 1 at 60fps
      console.log(timestamp)      // progressing timestamp
      console.log(absoluteDelta)  // 16.6666 at 60fps
    })

    When given a duration, the progress is beeing passed to the individual function.

    let duration = 1000
     
    let subscription = animFrame((progress, delta, timestamp, absoluteDelta) => {
      console.log(progress)       // 0..1000
    }, duration)

    To cancel simply call

    subscription.cancel()

    An elapsing subscription can also be iterated a number of times

    let iterate = 3
     
    let subscription = animFrame((progress) => {
      console.log(progress)       // 0..1000 ; 0..1000 ; 0..1000
    }, duration, iterate)

    Conribute

    All feedback is appreciated. Create an pull request or write an issue.

    Install

    npm i animation-frame-delta

    DownloadsWeekly Downloads

    8

    Version

    2.7.7

    License

    ISC

    Unpacked Size

    33.6 kB

    Total Files

    12

    Last publish

    Collaborators

    • avatar