Top Related Projects
JavaScript animation engine
GSAP (GreenSock Animation Platform), a JavaScript animation library for the modern web
JavaScript/TypeScript animation engine
🍿 A cross-browser library of CSS animations. As easy to use as an easy thing.
Reveal CSS animation as you scroll down a page
Simple animation libraries for delightful user interfaces
Quick Overview
Rebound-js is a JavaScript port of Facebook's Rebound library, originally developed for Android. It's a spring dynamics animation library that creates realistic, physics-based animations for web applications. Rebound-js allows developers to create smooth, natural-feeling animations using spring physics.
Pros
- Provides realistic, physics-based animations
- Lightweight and easy to integrate into web projects
- Offers fine-grained control over animation parameters
- Compatible with various JavaScript frameworks and libraries
Cons
- Limited documentation and examples compared to other animation libraries
- May require a deeper understanding of spring physics for optimal use
- Not actively maintained (last update was in 2017)
- Lacks some advanced features found in more modern animation libraries
Code Examples
Creating a simple spring animation:
const spring = new rebound.SpringSystem().createSpring();
spring.addListener({
onSpringUpdate: function(spring) {
const value = spring.getCurrentValue();
element.style.transform = `scale(${value})`;
}
});
spring.setEndValue(1);
Chaining multiple springs:
const springSystem = new rebound.SpringSystem();
const spring1 = springSystem.createSpring();
const spring2 = springSystem.createSpring();
spring1.addListener({
onSpringUpdate: function(spring) {
spring2.setEndValue(spring.getCurrentValue());
}
});
spring2.addListener({
onSpringUpdate: function(spring) {
element.style.opacity = spring.getCurrentValue();
}
});
spring1.setEndValue(1);
Customizing spring properties:
const spring = new rebound.SpringSystem().createSpring(40, 3);
spring.setOvershootClampingEnabled(true);
spring.setVelocity(5);
Getting Started
-
Include the Rebound-js library in your project:
<script src="https://cdnjs.cloudflare.com/ajax/libs/rebound/0.1.0/rebound.min.js"></script>
-
Create a spring system and a spring:
const springSystem = new rebound.SpringSystem(); const spring = springSystem.createSpring();
-
Add a listener to the spring and set its end value:
spring.addListener({ onSpringUpdate: function(spring) { const value = spring.getCurrentValue(); // Use the value to update your UI } }); spring.setEndValue(1);
Competitor Comparisons
JavaScript animation engine
Pros of anime
- More comprehensive animation library with a wider range of features
- Easier to use API with simpler syntax for creating animations
- Better documentation and examples for quick implementation
Cons of anime
- Larger file size, which may impact page load times
- Less focus on physics-based animations compared to rebound-js
Code Comparison
anime:
anime({
targets: '.element',
translateX: 250,
rotate: '1turn',
duration: 800,
easing: 'easeInOutQuad'
});
rebound-js:
const spring = rebound.createSpring(40, 3);
spring.addListener({
onSpringUpdate: (spring) => {
const value = spring.getCurrentValue();
element.style.transform = `translateX(${value * 250}px)`;
}
});
spring.setEndValue(1);
Summary
anime offers a more user-friendly and versatile animation solution, while rebound-js excels in physics-based animations. anime's simpler syntax and broader feature set make it more accessible for general web animations, but it comes at the cost of a larger file size. rebound-js provides more precise control over spring-based animations, which can be beneficial for specific use cases requiring realistic motion.
GSAP (GreenSock Animation Platform), a JavaScript animation library for the modern web
Pros of GSAP
- More comprehensive animation toolkit with a wider range of features
- Extensive documentation and community support
- Better performance for complex animations and large-scale projects
Cons of GSAP
- Steeper learning curve due to its extensive feature set
- Larger file size, which may impact load times for smaller projects
- Commercial license required for some advanced features
Code Comparison
GSAP:
gsap.to(".box", {duration: 1, x: 100, y: 50, rotation: 360});
Rebound-js:
var spring = rebound.createSpring(40, 3);
spring.addListener({
onSpringUpdate: function(spring) {
target.style.transform = `translate(${spring.getCurrentValue()}px, 0)`;
}
});
spring.setEndValue(100);
Summary
GSAP offers a more robust and feature-rich animation toolkit compared to Rebound-js, with better performance for complex animations. However, it comes with a steeper learning curve and potential licensing costs. Rebound-js, while more limited in scope, provides a simpler API focused on spring animations, which may be sufficient for projects with specific physics-based animation needs.
JavaScript/TypeScript animation engine
Pros of tween.js
- More comprehensive and feature-rich animation library
- Supports a wider range of easing functions and interpolation methods
- Active development and community support
Cons of tween.js
- Larger file size and potentially higher overhead
- Steeper learning curve due to more complex API
Code Comparison
tween.js:
const tween = new TWEEN.Tween({ x: 0 })
.to({ x: 100 }, 1000)
.easing(TWEEN.Easing.Quadratic.Out)
.onUpdate((object) => {
console.log(object.x);
})
.start();
rebound-js:
const spring = rebound.createSpring(1, 10);
spring.setEndValue(100);
spring.addListener({
onSpringUpdate: (spring) => {
console.log(spring.getCurrentValue());
}
});
tween.js offers more control over the animation process with a chainable API and various easing functions. rebound-js focuses on spring physics simulations with a simpler API. tween.js is better suited for complex animations, while rebound-js excels in creating natural, spring-like motion effects.
🍿 A cross-browser library of CSS animations. As easy to use as an easy thing.
Pros of animate.css
- Lightweight and easy to use with pre-defined CSS animations
- Extensive collection of ready-to-use animations
- No JavaScript required, pure CSS solution
Cons of animate.css
- Limited customization options for animations
- May require additional CSS for more complex animations
- Potential performance issues with excessive use of CSS animations
Code Comparison
animate.css:
.animate__animated {
animation-duration: 1s;
animation-fill-mode: both;
}
.animate__bounce {
animation-name: bounce;
}
rebound-js:
const spring = rebound.createSpring(40, 3);
spring.addListener({
onSpringUpdate: function(spring) {
const value = spring.getCurrentValue();
target.style.transform = `scale(${value})`;
}
});
animate.css provides pre-defined CSS classes for animations, while rebound-js uses JavaScript to create physics-based animations. animate.css is simpler to implement for basic animations, but rebound-js offers more control and customization for complex, dynamic animations.
animate.css is ideal for quick, predefined animations, while rebound-js is better suited for creating realistic, physics-based animations with fine-tuned control. The choice between the two depends on the specific requirements of the project and the desired level of animation complexity.
Reveal CSS animation as you scroll down a page
Pros of WOW
- Simpler to use and implement for basic scroll animations
- Lightweight and doesn't require additional dependencies
- Provides a wide range of pre-defined animation classes
Cons of WOW
- Less flexible for complex animations compared to Rebound.js
- Limited to scroll-based animations, while Rebound.js offers more versatile spring animations
- Lacks the physics-based approach that Rebound.js provides
Code Comparison
WOW:
new WOW().init();
<div class="wow fadeInUp" data-wow-duration="1s" data-wow-delay="0.5s">
Animate me!
</div>
Rebound.js:
const spring = rebound.createSpring(40, 3);
spring.addListener({
onSpringUpdate: (spring) => {
const value = spring.getCurrentValue();
element.style.transform = `scale(${value})`;
}
});
spring.setEndValue(1);
WOW focuses on declarative, class-based animations triggered by scrolling, while Rebound.js provides a more programmatic approach with physics-based spring animations. WOW is easier to implement for simple scroll animations, but Rebound.js offers greater flexibility and control for complex, dynamic animations.
Simple animation libraries for delightful user interfaces
Pros of Popmotion
- More comprehensive animation library with a wider range of features
- Active development and maintenance
- Better documentation and community support
Cons of Popmotion
- Larger file size and potentially higher performance overhead
- Steeper learning curve due to more complex API
Code Comparison
Rebound-js:
const spring = rebound.spring(1, 0.5);
spring.setEndValue(100);
spring.addListener({
onSpringUpdate: (spring) => {
console.log(spring.getCurrentValue());
}
});
Popmotion:
const spring = popmotion.spring({
from: 0,
to: 100,
stiffness: 100,
damping: 10
});
spring.start({
update: (v) => console.log(v),
complete: () => console.log('Spring animation complete')
});
Summary
Popmotion offers a more feature-rich and actively maintained animation library compared to Rebound-js. It provides a wider range of animation types and better documentation. However, this comes at the cost of a larger file size and a potentially steeper learning curve. The code comparison shows that both libraries use similar concepts for spring animations, but Popmotion's API is more flexible and provides more control over the animation parameters.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
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.
LICENSE
rebound-js
is BSD-licensed. We also provide an additional patent grant.
Top Related Projects
JavaScript animation engine
GSAP (GreenSock Animation Platform), a JavaScript animation library for the modern web
JavaScript/TypeScript animation engine
🍿 A cross-browser library of CSS animations. As easy to use as an easy thing.
Reveal CSS animation as you scroll down a page
Simple animation libraries for delightful user interfaces
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot