GithubHelp home page GithubHelp logo

animini's Introduction

npm (tag) npm bundle size

Demo

https://animini.vercel.app/

Installation

For the React DOM

yarn add @animini/react-dom

For React Three Fiber

yarn add @animini/react-three

Instructions

import { useDrag } from '@use-gesture/react'
import { useAnimate, spring } from '@animini/react-dom'

const easing = spring()

export default function App() {
  const [ref, api] = useAnimate()

  useDrag(
    ({ active, movement: [x, y] }) => {
      api.start({ scale: active ? 1.2 : 1, x: active ? x : 0, y: active ? y : 0 }, (k) => ({
        immediate: k !== 'scale' && active,
        easing
      }))
    },
    { target: ref }
  )

  return <div ref={ref} />
}

Easings

Lerp

Lerp is the lightest, fastest and default easing algorithm for Animini. It supports a factor attribute that will change the momentum of the lerp.

import { useAnimate, lerp } from '@animini/react-dom'

const easing = lerp({ factor: 0.05 })
api.start({ x: 100 }, { easing })

Spring

import { useAnimate, spring } from '@animini/react-dom'

const easing = spring({
  tension: 170, // spring tension
  friction: 26, // spring friction
  mass: 1, // target mass
  velocity // initial velocity
})

api.start({ x: 100 }, { easing })

Ease (Bezier)

import { useAnimate, ease } from '@animini/react-dom'

const easing = ease(
  300, // duration of the ease in ms
  [0.25, 0.1, 0.25, 1] // coordinates of the bezier curve
)

api.start({ x: 100 }, { easing })

Inertia

Inertia aims at emulating a thrown object. Inertia will not reach its destination and only works if the value is already moving or if the easing is given an initial velocity.

Inertia supports min and max bounds which the element will bounce against as a rubberband bouncing on a wall.

import { useAnimate, inertia } from '@animini/react-dom'

const easing = inertia({
  momentum: 0.998,     // momentum of the inertia
  velocity: undefined, // initial velocity (leave it undefined to use the current velocity of the value)
  min: -100,           // min bound
  max: 100,            // max bound
  rubberband = 0.15    // elasticity factor when reaching bounds defined by min / max
})

api.start({ x: 100 }, { easing })

animini's People

Contributors

dbismut avatar github-actions[bot] avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

izmaelmag

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.