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

rebound

v0.1.0

Published

A simple library for modeling spring dynamics

Downloads

93,660

Readme

Build
Status

Rebound

Rebound is a simple library that models Spring dynamics for the purpose of driving physical animations.

Origin

Rebound was originally written in Java to provide a lightweight physics system for Home and Chat Heads on Android. It's now been adopted by several other Android applications. This JavaScript port was written to provide a quick way to demonstrate Rebound animations on the web for a conference talk. Since then the JavaScript version has been used to build some really nice interfaces. Check out brandonwalkin.com for an example.

Overview

The Library provides a SpringSystem for maintaining a set of Spring objects and iterating those Springs through a physics solver loop until equilibrium is achieved. The Spring class is the basic animation driver provided by Rebound. By attaching a listener to a Spring, you can observe its motion. The observer function is notified of position changes on the spring as it solves for equilibrium. These position updates can be mapped to an animation range to drive animated property updates on your user interface elements (translation, rotation, scale, etc).

Check out the tests, and examples for more details.

Example

Here's a simple example. Pressing and releasing on the logo below will cause it to scale up and down with a springy animation.

<div style="text-align:center; margin-bottom:50px; margin-top:50px">
  <img
    src="http://facebook.github.io/rebound/images/rebound.png"
    id="logo"
  />
</div>
<script src="../rebound.min.js"></script>
<script>
  function scale(el, val) {
    el.style.mozTransform =
    el.style.msTransform =
    el.style.webkitTransform =
    el.style.transform = 'scale3d(' + val + ', ' + val + ', 1)';
  }
  var el = document.getElementById('logo');

  var springSystem = new rebound.SpringSystem();
  var spring = springSystem.createSpring(50, 3);
  spring.addListener({
    onSpringUpdate: function(spring) {
      var val = spring.getCurrentValue();
      val = rebound.MathUtil.mapValueInRange(val, 0, 1, 1, 0.5);
      scale(el, val);
    }
  });

  el.addEventListener('mousedown', function() {
    spring.setEndValue(1);
  });

  el.addEventListener('mouseout', function() {
    spring.setEndValue(0);
  });

  el.addEventListener('mouseup', function() {
    spring.setEndValue(0);
  });
</script>

Here's how it works.

// Get a reference to the logo element.
var el = document.getElementById('logo');

// create a SpringSystem and a Spring with a bouncy config.
var springSystem = new rebound.SpringSystem();
var spring = springSystem.createSpring(50, 3);

// Add a listener to the spring. Every time the physics
// solver updates the Spring's value onSpringUpdate will
// be called.
spring.addListener({
  onSpringUpdate: function(spring) {
    var val = spring.getCurrentValue();
    val = rebound.MathUtil
                 .mapValueInRange(val, 0, 1, 1, 0.5);
    scale(el, val);
  }
});

// Listen for mouse down/up/out and toggle the
//springs endValue from 0 to 1.
el.addEventListener('mousedown', function() {
  spring.setEndValue(1);
});

el.addEventListener('mouseout', function() {
  spring.setEndValue(0);
});

el.addEventListener('mouseup', function() {
  spring.setEndValue(0);
});

// Helper for scaling an element with css transforms.
function scale(el, val) {
  el.style.mozTransform =
  el.style.msTransform =
  el.style.webkitTransform =
  el.style.transform = 'scale3d(' +
    val + ', ' + val + ', 1)';
}

Code of Conduct

Facebook has adopted a Code of Conduct that we expect project participants to adhere to. Please read the full text so that you can understand what actions will and will not be tolerated.