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

@meteora-digital/tween

v1.0.5

Published

A class to tween number values - can be used to animate element styles

Downloads

11

Readme

Tween

An easy to use tweening class. Any number can be tweened from one value to another over a set period of time. The class will handle the tweening, you do the rest!

Installation

npm i @meteora-digital/tween
yarn add @meteora-digital/tween

Usage

HTML

<section class="banner">
  <div class="banner__image" style="background-image: url('path/to/your/image.jpg');"></div>
</section>

JavaScript

import Tween from '@meteora-digital/tween';

const banner = document.querySelector('.banner');
const image = document.querySelector('.banner__image');

Create a controller!

const Controller = new Tween({
  fps: 60,
});

| Option | Type | Description | Default | |--------|------|-------------|---------| | fps | number | the frame rate for the tween | 60 |

Tweening - smoothly animate a number from one value to another.

Controller.tween({ from: 0, to: 100 }, (value) => image.style.opacity = value / 100, 300);

The tween method will load the controller with a new task, it can currently only have one task at a time. the tween() method takes 3 arguments:

| Type | Description | Defaults | |------|-------------|----------| | object | Two keys - "from" and "to" | from: 0, to: 100 | | function | A function that returns the current value | (value) => console.log(value); | | duration | A length of time in milliseconds | 300 |

Note this function uses rounding to stop the function from looping continuously without any visual changes, therefore is is best to use whole numbers for situations like the example above.

Stopping the tween

Controller.stop();

If we ever need to stop the animation we can use the stop() method

Restarting the tween

Controller.start();

If we have stopped the animation we can restart it using the start() method

Callbacks

The available callbacks are 'start', 'stop' and 'end'.

| Event | Description | |------|-------------| | start | Triggered when the animation starts | | stop | Triggered when the animation is stopped via the .stop() method | | end | Triggered when the animation has come to it's end naturally |

Controller.on('start', () => console.log('Animation has started!'));

If we have stopped the animation we can restart it using the start() method

License

MIT