1.1.0 • Published 4 years ago

@minax/animate-scroll v1.1.0

Weekly downloads
1
License
ISC
Repository
github
Last release
4 years ago

@minax/animate-scroll · npm

Let the elements have an animated scroll in the React project.

Install

npm i --save @minax/animate-scroll

Usage

import animate from '@minax/animate-scroll'
animate(start, end, callback[, options])

options is an object composed of the following key

nametypedefaultdescription
startnumber|number[]animation start point(s)
endnumber|number[]animation end point(s)
callbackfunctioncallback with current value(s) when update
spendTimenumber600animation duration(ms)
animationFuncAnimationType'linear'animation function

AnimationType

type AnimationType = 'linear' |
  'easeInSine' | 'easeOutSine' | 'easeInOutSine' |
  'easeInQuad' | 'easeOutQuad' | 'easeInOutQuad' |
  'easeInCubic' | 'easeOutCubic' | 'easeInOutCubic' |
  'easeInQuart' | 'easeOutQuart' | 'easeInOutQuart' |
  'easeInQuint' | 'easeOutQuint' | 'easeInOutQuint' |
  'easeInExpo' | 'easeOutExpo' | 'easeInOutExpo' |
  'easeInCirc' | 'easeOutCirc' | 'easeInOutCirc' |
  'easeInBack' | 'easeOutBack' | 'easeInOutBack' |
  'easeInElastic' | 'easeOutElastic' | 'easeInOutElastic' |
  'easeInBounce' | 'easeOutBounce' | 'easeInOutBounce'

Quick Overview

import animate from '@minax/animate-scroll'

animate(0, 100, (value) => {})
animate([0, 0], [100, 200], (values) => {})
import React, { useEffect, useRef } from 'react';

import animate from '@minax/animate-scroll'

function App() {
  const r = useRef(null)
  useEffect(() => {
    setInterval(() => {
      if (r.current) {
        const { scrollTop, scrollHeight } = r.current
        animate(
          scrollTop,
          Math.random() * scrollHeight,
          (now) => {
            r.current.scrollTop = now
          },
          {
            spendTime: 1000
          }
        )
      }
    }, 1500);
  })
  return (
    <div
      ref={r}
      style={{
        height: 400,
        margin: 24,
        overflow: 'auto',
        textAlign: 'center',
        border: '1px solid #000'
      }}
    >
      {
        new Array(40).fill(1).map((i, index) => (
          <div key={index} style={{ fontSize: 40 }}>{index}</div>
        ))
      }
    </div>
  );
}
1.1.0

4 years ago

1.0.1

5 years ago

1.0.0

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago

0.0.2

5 years ago

0.0.1

5 years ago