react-tween-time
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

react-tween-time

Bare Necessities for React Animations

NPM JavaScript Style Guide

Install

npm install --save react-tween-time

Usage

import React from 'react'
import { easing, useTweenTime } from 'react-tween-time'

const Example = () => {
  // after 1000 milliseconds t scales from 0 to 1 in two seconds
  const [t] = useTweenTime({
    startAt: 1000,
    mode: 'autostart',
    duration: 2000,
    easingFn: easing.inOutQuint
  })
  return (
    <div
      style={{
        transform: `translateX(${t * 100}px)`
      }}
    >
      Moving...
    </div>
  )
}

Control manually

const [t, anim] = useTweenTime({
  startAt: 1000,
  mode: 'manualstart', // does not start automatically
  duration: 2000,
  easingFn: easing.inOutQuint
})

// start animation
anim.start()
// pause animation
anim.pause()
// continue paused animation
anim.resume()

React to the animation end

const [t, anim] = useTweenTime({
  onEnd: () => {
    /* animation has ended */
  }
})

License

MIT © terotests

Readme

Keywords

none

Package Sidebar

Install

npm i react-tween-time

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

40.3 kB

Total Files

9

Last publish

Collaborators

  • terotests