npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

request-animation-number

v1.0.8

Published

Light animation library based on requestanimationframe

Downloads

1,321

Readme

Request Animation Number

Features

  • Light animation library for modern JavaScript.

  • Based on requestAnimationFrame() method which generates smooth animation and transitions.

  • Matches animation speed on different screens refresh rates. Tested on 60Hz and 145Hz

  • Animate anything takes a value as number.

    E.g. scrolling , width, color ...

  • Contains most popular Easing functions with the ability to provide your own.

    E.g. Ease In, Ease Out, Ease In Out, .... and more

  • Check easings.net to learn more.

Syntax

  • requestNum(options: object, callback: (...animatedNumbers: number[]) => void)

Example

import { requestNum } from 'request-animation-number';

const element = document.getElementById('square');

const animationOptions = {
  from: [0, 1],
  to: [90, 2],
  duration: 500,
  easingFunction: 'easeInOutBack',
};

requestNum(animationOptions, (rotate, scale) => {
  element.style.transform = `rotate(${rotate}deg) scale(${scale})`;
  // ...
});

How to animate colors

  • you can ether use rgb values as an array of numbers or you can use colorToArr() method to convert colors from string to array of numbers which represents rgba values.

  • colorToArr() method takes a string and returns an array of number as [r, g, b, a].

  • colorToArr() accept following formats: rgb(r, g, b) , rgba(r, g, b, a) , hex (e.g. "#ffffff ") , color name (e.g. "red")

Example for colors animation

import { requestNum, colorToArr } from 'request-animation-number';

const element = document.getElementById('circle');

const animationOptions = {
  from: colorToArr('brown'), // returns [163, 54, 54]
  to: colorToArr('#000000'), // returns [0, 0, 0]
  duration: 1000,
  easingFunction: 'easeInSine',
};

requestNum(animationOptions, (r, g, b) => {
  element.style.backgroundColor = `rgb(${r} ${g} ${b})`;
});

Sequential animation

  • requestNum() is an asynchronous function.

  • You can use await to create sequences of animation by waiting for the first animation to end then starting the next.

Example for sequential animation

import { requestNum } from 'request-animation-number';

async function animate() {
  const circle1 = document.getElementById('circle1');
  const circle2 = document.getElementById('circle2');

  await requestNum({ to: 350 }, left => (circle1.style.left = left + 'px'));

  requestNum({ to: 350 }, right => (circle2.style.right = right + 'px'));
}

animate();
  • Note that if replay set to -1 it will repeat infinitely.

Another way to make sequential animation without using asynchronous function

import { requestNum } from 'request-animation-number';

function animate() {
  const circle1 = document.getElementById('circle1');
  const circle2 = document.getElementById('circle2');

  requestNum({ to: 350 }, left => {
    circle1.style.left = left + 'px';

    // detect when the animation ends
    if (left === 350) {
      requestNum({ to: 350 }, right => (circle2.style.right = right + 'px'));
      // ...
    }
  });
}

animate();

Options [Object]

from: [ Number | Numbers[] ] [optional]

  • Animation will starts form this number/s.
  • Takes one number or array of numbers or if a value not provided will be set to 0 by default.
  • Initial Value 0 | [0, 0 , ...]

to: [ Number | Numbers[] ]

  • Animation will ends at this number/s.
  • takes one number or array of numbers.

duration: [Number] [optional]

  • The duration the function will take to change the number/s (in milliseconds).
  • Initial Value 350.

delay: [Number] [optional]

  • Delay time before starting the animation (in milliseconds).
  • Initial Value 0.

easingFunction: [ String | Function ] [optional]

  • Easing functions specify the rate of change of the number over time.
  • Takes a String or Function.
  • Initial Value "linear".
  • Avaliable Easing functions : "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"
  • Check easings.net to learn more.
  • If you want to provide your own timing-function make sure that the function takes one parameter and returns one value.
function easeInQuad(x) {
  return x * x;
}

yoyo: [boolean] [optional]

  • Animate back to the starting point if true.
  • Initial Value false.

yoyoDuration: [Number] [optional]

  • The duration to go back to starting point (in milliseconds).
  • Initial Value duration.

yoyoDelay: [Number] [optional]

  • Delay time before starting the yoyo animation (in milliseconds).
  • Initial Value delay.

replay: [Number] [optional]

  • Replay count after the first play.
  • infinite if replay value is set to -1.
  • Initial Value 0.