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

simple-animate

v0.0.5

Published

Simple and minimal animation library

Downloads

2

Readme

Simple and minimal animation library

This is a small and minimalistic animation library. You can only animate single value properties like opacity, width or height for example. If you want to animate properties like margin, you have to use every property separately as margin-top, margin-right etc.

If you find any issues or bugs with this package, feel free to open an issue on github and i will try to resolve it as fast as possible. Or simply fix the bugs yourself and open a pull request.

Installation

$ npm install simple-animate --save

Importing

// ES6 Module
import { polyfill, animate, animateAsPromise } from 'simple-animate';

// CommomJS
const SimpleAnimate = require('simple-animate');

API

animate(el, props [, duration [, easing] [, callback [, forceCallback] ] ])

Animate an element to target props.

Returns: Function - Returns a function which cancels the animation if called

| Param | Type | Default | Description | | --- | --- | --- | --- | | el | Element | | The Element to animate | | props | Object | | The properties & values you want it to look like | | [duration] | Number | 400 | Duration of the animation in ms | [easing] | String | linear | Easing to be used | [callback] | function | | Callback function to execute when the animation finished | | [forceCallback] | boolean | false | If true will force the callback to be executed even if the animation got canceled |

Example

// ES6 Module
import { animate } from 'simple-animate';

// CommonJS
const animate = require('simple-animate').animate;

const div = document.querySelector('div');

// Animate div to target props without a callback
animate(div, { width: '200px', height: '100px' }, 500, 'easeInOutCubic');


// Animate div to target props with a callback
animate(div, { width: '300px', height: '200px' }, 500, 'easeInOutCubic', function () {
    console.log('Animation finished, YAY!');
});

// Animate div to target props with a callback, but animation gets canceled and callback will not be reached
const cancelAnimation = animate(div, { width: '200px', height: '100px' }, 500, 'easeInOutCubic', function () {
    console.log('This will not be logged');
});

// Cancel animation after 200ms
setTimeout(cancelAnimation, 200);

// Animate div to target props with a callback, animation will be canceled but callback will be executed anyway
const cancelAnimation = animate(div, { width: '200px', height: '100px' }, 500, 'easeInOutCubic', function () {
    console.log('Forced callback execution');
}, true);

// Cancel animation after 200ms
setTimeout(cancelAnimation, 200);

animateAsPromise(el, props [, duration [, easing] ])

This is the same as animate, but returns a Promise. This looks nicer, but can't be canceled.

Returns: Promise - Returns a Promise which resolves when the animation ends.

| Param | Type | Default | Description | | --- | --- | --- | --- | | el | Element | | The Element to animate | | props | Object | | The properties & values you want it to look like | | [duration] | Number | 400 | Duration of the animation in ms | [easing] | String | linear | Easing to be used

Example

// ES6 Module
import { animateAsPromise } from 'simple-animate';

// CommonJS
const animateAsPromise = require('simple-animate').animateAsPromise;

const div = document.querySelector('div');

// Animate div to target props without a callback
animateAsPromise(div, { width: '200px', height: '100px' }, 500, 'easeInOutCubic');

// Animate div to target props with a callback
animateAsPromise(div, { width: '300px', height: '200px' }, 500, 'easeInOutCubic')
    .then(function () {
        console.log('Animation finished, YAY!');
    });

// Animate div to target props with default duration & easing
animateAsPromise(div, { width: '300px', height: '200px' })
    .then(function () {
        console.log('Animation finished, YAY!');
    });

polyfill([animatePropName [, animateAsPromisePropName] ])

This function will add animate and animateAsPromise to the Element.prototype. The functions animate and animateAsPromise can be used as shown above with one difference. There will be no need to use the el property, since that will be taken care of :)

| Param | Type | Default | Description | | --- | --- | --- | --- | | animatePropName | String | customAnimate | Propertyname you want to allocate on the Element.prototype for the animate function | | animateAsPromisePropName | String | customAnimateAsPromise | Propertyname you want to allocate on the Element.prototype for the animateAsPromise function |

Example

// ES6 Module
import { polyfill } from 'simple-animate';

// CommonJS
const polyfill = require('simple-animate').polyfill;

// This adds customAnimate and customAnimateAsPromise to Element.prototype
polyfill();

// Fetching Element from DOM
const div = document.querySelector('div');

// Normal animation
div.customAnimate({ width: '200px', height: '100px' }, 500, 'easeInOutCubic');

// Animation which returns a promise
div.customAnimateAsPromise({ width: '300px', height: '200px' }, 500, 'easeInOutCubic')
    .then(function () {
        console.log('Animation finished, YAY!');
    });

Easings

All credit for the easing function goes to gre
Available easings:

  • linear
  • easeInQuad
  • easeOutQuad
  • easeInOutQuad
  • easeInCubic
  • easeOutCubic
  • easeInOutCubic
  • easeInQuart
  • easeOutQuart
  • easeInOutQuart
  • easeInQuint
  • easeOutQuint
  • easeInOutQuint

MIT © Christian Sany