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

cude-animations

v1.13.0

Published

cudeAnimations is a lightweight simple JavaScript library that can be used to create custom animations.

Downloads

87

Readme

cudeAnimations.js

cudeAnimations is a lightweight simple JavaScript library that can be used to create custom animations.

The minified library weights 8kb before gzip. It relies on a promise polyfill, so if your project doesn't include that beforehand, you can use cudeAnimations.withpoly.min.js instead of cudeAnimations.min.js.

When using the polyfied version, cudeAnimations.js supports all browsers.

Try the demos

Installation

Simply include the cudeAnimations.min.js file from the dist folder in your project or install via npm using the package name cude-animations.

After including the file the classes are available through the global variable cudeAnimations.

If using ES6 modules, the library exports the following modules:

  • ScrollAnimator (Class) - not documented yet
  • Animate (Class)

Animate usage:

When instantiating a new animation, an options paramter is expected. The options parameter is an object containing the following parameters:

  • start = {number} The value to start the animation from.
  • end = {number} The value to end the animation at.
  • duration = {number} (optional) duration of the animation in ms. Default: 250.
  • reverse = {boolean} (optional) If true animates from end to start value. Default: false.
  • customEasing = {(t:number, b:number, c:number, d:number)=>void} (option). Default: easings.easeInOutExpo. See section below about custom easing functions.
  • target = {string} query of html elements. Needs to be specified if the manipulator is not specified. When used, the library will replace the inneHTML of the elements with the value (rounded to 0 decimals).
  • manipulator = {(value:number, end:boolean)=>void} Is called once for each keyframe, needs to be specified if the target is not specified. The manipulator is the recommended way of controlling animation. Keep this function as efficient as possible, as it may be called often.

Example using target:

var options = {
  target: ".animate-this-element",
  start: 0,
  end: 100,
  duration: 1000
}
var animation = new cudeAnimations.Animate(options)
animation.start()

Same example using manipulator:

//  Find the element manually. 
//  Don't do this inside the manipulator function
var element = document.querySelector(".animate-counter span")

//  Keep this function as efficient as possible, as it may be called many times
manipulator = function(val){
  element.innerHTML = val
}

var options = {
  manipulator: manipulator,
  start: 0,
  end: 100,
  duration: 1000
}

var animation = new cudeAnimations.Animate(options)
animation.start()

The start() method returns a Promise that is resolved once the animation is finished. This can be used to easily create chained animations.

Example of chained animation:

var options = {
  target: ".animate-this-element",
  start: 0,
  end: 100,
  duration: 1000
}

var options2 = {
  target: ".animate-this-element-after",
  start: 0,
  end: 100,
  duration: 1000
}

var animation = new cudeAnimations.Animate(options)
var animation2 = new cudeAnimations.Animate(options2)

animation
  .start()
  .then(animation2.start)

Custom easing:

You can optionally apply your custom easing function, which will receive 4 parameters necessary to calculate a Bezier curve:

  • t (the current time);
  • b (the beginning value);
  • c (the difference between the beginning and destination value);
  • d (the total time of the tween).

You could use any of Robert Penner's easing functions.

If you don't specify a custom easing function, the default is easeInOutExpo.

Example:

const linear = (t, b, c, d) => {
  return c * t / d + b;
}

const options = {
  target: ".mySelector",
  customEasing: linear
  start: 0,
  end: 100,
  duration: 1000,
}

new cudeAnimations.Animate(options).start()

Scroll Animation:

This library also contains methods for controlling the animatino using scroll, instead of a duration. Still needs to be documented. See scrollAnimation for example.