You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Feb 2, 2021. It is now read-only.
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).
// Get a reference to the logo element.varel=document.getElementById('logo');// create a SpringSystem and a Spring with a bouncy config.varspringSystem=newrebound.SpringSystem();varspring=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){varval=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.functionscale(el,val){el.style.mozTransform=el.style.msTransform=el.style.webkitTransform=el.style.transform='scale3d('+val+', '+val+', 1)';}
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.
LICENSE
rebound-js is BSD-licensed. We also provide an additional patent grant.