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

@cheprasov/web-animation

v0.1.7

Published

A Class for driving animated content on the web is based on requestAnimationFrame for performance.

Downloads

6

Readme

MIT license

@cheprasov/web-animation

Simple class WebAnimation for perform an animation on the web via JavaScript. It is based on requestAnimationFrame for performance.

Features:
  • Based on requestAnimationFrame for performance.
  • It allows to use any functions fo easing.
  • Easy to use for looped animation.

1. How to install

> npm install @cheprasov/web-animation
import WebAnimation from '@cheprasov/web-animation';

2. Quick examples

Example 1: Moving div to left on 500px for 2 sec with easing f(x) = n^2.

import WebAnimation from '@cheprasov/web-animation';

const div1 = document.getElementById('div1');

const animation = new WebAnimation({
    duration: 2000,
    easing: n => n ** 2,
});

const move = 500;

animation.setOnStep((progress) => {
    const shiftX = progress.tween * move;
    div1.style.transform = `translate3d(${shiftX}px, 0, 0)`;
});

animation.setOnFinish(() => {
    div1.style.transform = 'none';
    div1.style.left = `${move}px`;
});

animation.run();

3. Documentation

constructor ( options = {...} )

  • duration: number, optional, default = 1000. Duration time (ms) for animation.

  • easing: function, optional, default = (n => n). Easing function for animation tween. Arguments:

    • ratio: number - Ratio of elapsedTime / duration

    Returns number. Return of the function will be used like tween for animation progress.

  • rAF: function, optional, default = window.requestAnimationFrame. Function for animation tick. Arguments:

    • function - the functions which should be called on animation tick.
  • onStep: function, optional, default = null. Function will be called on each animation step. Arguments:

    • progress - object with progress state of animation (see more below).
    • animation - link to instance of WebAnimation class.
  • onStop: function, optional, default = null. Function will be called when animation terminated by call stop() method. Arguments:

    • progress - object with progress state of animation (see more below).
    • animation - link to instance of WebAnimation class.
  • onFinish: function, optional, default = null. Function will be called when animation is finished. Arguments:

    • progress - object with progress state of animation (see more below).
    • animation - link to instance of WebAnimation class.

Example:

const options = {
    duration: 2000,
    easing: n => n ** 2,
    onStep: (progress) => {
        someDiv.style.opacity = progress.tween;
    },
    onFinish: (progress) => {
        someDiv.style.display = 'none';
    },
};

const animation = new WebAnimation(options);

Object progress for onStep, onStop, onFinish methods

  • elapsedTime: number - Elapsed time
  • ratio: number - Ratio of elapsed time / duration. 0 <= n <= 1
  • tween: number - Tween value for animation. tween = easing(ratio)
  • isFinished: boolean - Is animation finished?

Example:

{
    elapsedTime: 1000,
    ratio: 0.2,
    tween: 0.04,
    isFinished: false,
}

run()

Method run to perform animation.

const animation = new WebAnimation();
animation.run();

stop()

Method run to stop animation. It will call onStop callback;

const animation = new WebAnimation({
    duration: 1000,
    onStop: (progress) => {
        console.log('Animation progress', progress);    
    },
});

animation.run();

setTimeout(() => {
    animation.stop();
}, 500);

setOnStop(function)

Setter for onStop callback.

animation.setOnStop((progress, animation) => {
    console.log('Animation is stopped');
})

setOnStep(function)

Setter for onStep callback.

animation.setOnStep((progress, animation) => {
    console.log('Animation step');
})

setOnFinish(function)

Setter for onFinish callback.

animation.setOnFinish((progress, animation) => {
    console.log('Animation is finished');
})

getProgress(): progress

Get progress state of animation. See progress object above.

setTimeout(() => {
    console.log('Animation progress', animation.getProgress());
}, 100);

Something does not work

Feel free to fork project, fix bugs, tests and finally request for pull