Create beautiful CSS3 powered animations in no time.

Related tags

Animations bounce.js
Overview

Bounce.js

Bounce.js is a tool and JS library for generating beautiful CSS3 powered keyframe animations. The tool on bouncejs.com allows you to generate static keyframes that can be used without any extra JavaScript, but if you'd like your application to generate these on the fly, you can use the Bounce.js library.

Installation

The library is available to install from Bower or NPM:

$ bower install bounce.js 
# OR
$ npm install bounce.js

You can also view and download all releases from here.

Usage

To create an animation, instantiate a new Bounce object:

var bounce = new Bounce();

The Bounce object is what you'll use to first build your animation from the different components scale, rotate, translate and skew. This can then either be defined as a named animation for later use, or directly applied to elements on the page.

Adding Animation Components

As mentioned above, you'll use the scale, rotate, translate and skew methods to build your animation, just like with the Bounce.js tool. All of these methods accept a number of common options (explained further down) and from and to parameters that define the start and end points of the animation. Note that all of these methods are chainable.

scale

var bounce = new Bounce();
bounce.scale({
  from: { x: 0.5, y: 0.5 },
  to: { x: 1, y: 1 }
});

The from and to parameters define the scale of the element on X (width) and Y (height) as a ratio. The example above animates the element from half size to full. (See it in action)

rotate

var bounce = new Bounce();
bounce.rotate({
  from: 0,
  to: 90
});

The from and to parameters define the rotation of the element in degrees. The example above animates the element a quarter rotation to the right. (See it in action)

translate

var bounce = new Bounce();
bounce.translate({
  from: { x: 0, y: 0 },
  to: { x: 100, y: 0 }
});

The from and to parameters define the translation (position) of the element on X and Y in pixels. The example above animates the element 100 pixels to the right. (See it in action)

skew

var bounce = new Bounce();
bounce.skew({
  from: { x: 0, y: 0 },
  to: { x: 20, y: 0 }
});

The from and to parameters define the skew of the element on X and Y in degrees. The example above animates the skew of the element 20 degrees on the horizontal axis. (See it in action)

Common Animation Parameters

All of the above methods accept these additional parameters:

  • duration: The duration of the animation in ms. Defaults to 1000.
  • delay: The delay of the animation in ms. Defaults to 0.
  • easing: One of "bounce", "sway", "hardbounce", "hardsway". These are the same as in the "Easing" menu in the tool. Defaults to "bounce".
  • bounces: The number of bounces in the animation. Defaults to 4.
  • stiffness: The stiffness of the bounces in the animation, should be a value between 1 and 5. Defaults to 3.

Using the Animation

Once you've built your animation, you can either choose to define it as a named keyframe animation, or directly apply it to any element in the DOM.

define

var bounce = new Bounce();
bounce.rotate({
  from: 0,
  to: 90
});
bounce.define("my-animation");

Defines an animation with the given name. The animation can then be used in your CSS with animation: my-animation 1s linear both;.

applyTo

var bounce = new Bounce();
bounce.rotate({
  from: 0,
  to: 90
});
bounce.applyTo(document.querySelectorAll(".animation-target"));
// or with jQuery: bounce.applyTo($(".animation-target"));

Directly applies the animation to a single or a list of elements. This method also accepts a number of options:

  • loop: Loops the animation infinitely if set to true. Defaults to false.
  • remove: Removes the animation once it is complete. If your animation ends in a state different from what the element had before, the element will return to its original state in some browsers. Defaults to false
  • onComplete: A callback function to be run after the animation is complete.

If you're using jQuery, the method will return a promise to be used instead of the onComplete parameter:

bounce.applyTo($(".animation-target")).then(function() { 
  console.log("Animation Complete"); 
});

Remove

An animation can also manually be removed once it has been defined:

bounce.remove()

Browser Support

You can check for support in the current browser with:

Bounce.isSupported()

The library should work in all browser that support both 3D transforms and keyframe animations.

Full Example

Here's a full example of building the Splat animation preset in the tool and applying it to an element with class animation-target.

var bounce = new Bounce();
bounce
  .translate({
    from: { x: -300, y: 0 },
    to: { x: 0, y: 0 },
    duration: 600,
    stiffness: 4
  })
  .scale({
    from: { x: 1, y: 1 },
    to: { x: 0.1, y: 2.3 },
    easing: "sway",
    duration: 800,
    delay: 65,
    stiffness: 2
  })
  .scale({
    from: { x: 1, y: 1},
    to: { x: 5, y: 1 },
    easing: "sway",
    duration: 300,
    delay: 30,
  })
  .applyTo(document.querySelectorAll(".animation-target"));

Developing

If you'd like to run the Bounce.js site locally, and edit the JavaScript library, you can do so by cloning this repo and running the following commands (assuming that you have Node, NPM and Bower installed):

# Install dependencies
$ npm install
$ bower install

# Start the server on localhost:9000. Watches for changes, automatically recompiles files and refreshes the browser.
$ grunt serve 

# Run the tests
$ grunt test
Comments
  • Simplify

    Simplify

    Very nice tool, but many animations gets quite a lot of CSS-code for most of the presets. A "simplify" button would be nice, so the code maybe do the animation in fever steps and therefore saves some kb. Maybe a slider, so the user can find the perfect point between smooth animation and an acceptable number of CSS-lines.

    opened by universaldenmark 6
  • Starting Points of Animations

    Starting Points of Animations

    Is it possible to have starting points for the animations? for example, if I'm using the "jelly" preset, the animated elements animation starts at coordinates center center. Can I change them to start top left for example. x:0 and y:0?

    opened by plisvb 3
  • Multiple animations in one page

    Multiple animations in one page

    Hi, thanks for creating great tool. Is it possible to add multiple animation into one page? I tried to create two different classes, but its only applying the last animation style.

    Thanks

    opened by debrajrakshit 3
  • IE doesn't support Element#remove

    IE doesn't support Element#remove

    We noticed IE was throwing when we passed the remove: true option or called instance.remove() no IE yet supports the DOM4 remove method so I added some code to check if it exists and polyfill if not. I also attached it to the window as in our case we load our script in an iframe and need to override the window object that bounce uses internally.

    opened by ryanseddon 2
  • The URL in the generated CSS breaks the sass compiler

    The URL in the generated CSS breaks the sass compiler

    Reported by https://twitter.com/ThiRaBr_TNK/status/476287253640396800. A quick fix would be to encode the URL, but a nicer solution would probably be to fetch a short URL when the CSS is exported.

    opened by JoelBesada 2
  • Text inside the animated div is getting blurred

    Text inside the animated div is getting blurred

    When a div is animated using Swoosh animation (example) , the text inside the div is getting blur and during the animation and getting set properly after the animation.

    Fiddle example

    opened by iamgraviteja 1
  • Naming animations

    Naming animations

    Great project! To make copying and pasting the exported css easier, it would be nice to add a field to set the animation name so you don't have to change that in your code every time. Also omit the .animation-target {} rule from the output and put that in some documentation instead. This would make the workflow super efficient. Thanks again, great job.

    feature-request 
    opened by gpoitch 1
  • Use numbers instead of text input where appropriate.

    Use numbers instead of text input where appropriate.

    Since we expect this inputs to only ever accept numbers they should be number inputs because this allows for using number keys to change the value, as well as the arrows for certain browsers.

    opened by cranesandcaff 1
  • Smarter keyframes

    Smarter keyframes

    This reduces the number of keyframes that the web tool generates by being smarter with where the keyframes are placed. The default bounce easing will now only have 10 keyframes instead of 30, without losing any significant fidelity of the easing curve.

    opened by JoelBesada 0
  • -webkit-transform inside unprefixed keyframes is unnecessary

    -webkit-transform inside unprefixed keyframes is unnecessary

    If you compare the support tables on caniuse.com, no browser has ever unprefixed keyframes before transforms. For more complex animations, this needlessly bloats the code by a significant amount.

    opened by ghost 0
  • [FEATURE REQUEST] Allow percentages in from/to for components in applyTo

    [FEATURE REQUEST] Allow percentages in from/to for components in applyTo

    The general idea is to allow something like this:

    $elements = $('#foo') # assume <div> element with width and height equal to 100px
    
    animation = new Bounce()
    
    animation.translate(
      from: { x: 0, y: 0 },
      to: { x: 0, y: '100%' }, # Translate up 100% (at time of evaluation, 100px)
      easing: 'bounce',
      duration: 1500,
      delay: 0,
      bounces: 2,
      stiffness: 5
    ).translate(
      from: { x: 0, y: 0 },
      to: { x: '100%', y: 0 }, # Translate right 100% (at time of evaluation, 100px)
      easing: 'bounce',
      duration: 1500,
      delay: 0,
      bounces: 2,
      stiffness: 5
    )
    
    animation.applyTo($elements)
    

    The reason is that it makes bounce animations much more dynamic with respect to either the current DOM properties of the applied elements (and could be even more flexible if we could interpolate with the current values established by previous components in the chain).

    EDIT: After further thought and inspection, I'm wondering - is this even possible with the usage of matrices?

    Let me know. Thanks, cheers.

    opened by aeberlin 3
  • Naming in bounce.js

    Naming in bounce.js

    Hey! Great project! Im new to GitHub so I hope this is the correct place to post this. Love the webapp but Bounce.js is so crunk. Again, props bro.

    I was experimenting with saving multiple instances of Bounce & then reapplying them to other elements. The object automatically gets renamed because in "Bounce.prototype.applyTo" the "this.define()" is passed without a name, so if you did have a name it gets ignored/reset.

    I was kind of wondering if there was a reason behind this? Thanks.

    Bounce.prototype.define = function(name) {
        this.name = name || Bounce.generateName();
        this.styleElement = document.createElement("style");
        this.styleElement.innerHTML = this.getKeyframeCSS({
          name: this.name,
          prefix: true
        });
        document.body.appendChild(this.styleElement);
        return this;
      };
    
      Bounce.prototype.applyTo = function(elements, options) {
        var css, deferred, element, prefix, prefixes, _i, _j, _len, _len1, _ref;
        if (options == null) {
          options = {};
        }
        this.define();
        if (!elements.length) {
          elements = [elements];
        }
        prefixes = this.getPrefixes();
        deferred = null;
    ...
    
    opened by fcampas 0
  • Visualizing the easing curves

    Visualizing the easing curves

    Hi Joel, I've just read your article on Medium and I was thinking it would be nice to be able to visualise the animation curves (original and approximate) in Bounce.js :) What do you think?

    opened by og2t 0
Releases(0.8.2)
  • 0.8.2(Feb 16, 2015)

    • Fixed IE compatibility issue with the bounce.remove method
    • Added optimized option to getKeyframes and getKeyframeCSS to optimize number of keyframes
    Source code(tar.gz)
    Source code(zip)
Nebula is a lightweight (1kb compressed) JavaScript library that creates beautiful universe animations.

Nebula is a lightweight JavaScript library for creating beautiful universe animations. Including configurable Stars, Nebulas, Comets, Planets and Suns. Compatible with SSR

Florian DE LA COMBLE 34 Nov 25, 2022
Javascript library to create physics-based animations

Dynamics.js Dynamics.js is a JavaScript library to create physics-based animations To see some demos, check out dynamicsjs.com. Usage Download: GitHub

Michael Villar 7.5k Jan 6, 2023
Matteo Bruni 4.7k Jan 4, 2023
Super-smooth CSS3 transformations and transitions for jQuery

jQuery Transit Super-smooth CSS3 transformations and transitions for jQuery jQuery Transit is a plugin for to help you do CSS transformations and tran

Rico Sta. Cruz 7.4k Dec 23, 2022
CSS3 backed JavaScript animation framework

Move.js CSS3 JavaScript animation framework. About Move.js is a small JavaScript library making CSS3 backed animation extremely simple and elegant. Be

Sloth 4.7k Dec 30, 2022
It's a presentation framework based on the power of CSS3 transforms and transitions in modern browsers and inspired by the idea behind prezi.com.

impress.js It's a presentation framework based on the power of CSS3 transforms and transitions in modern browsers and inspired by the idea behind prez

impress.js 37k Jan 2, 2023
🍿 A cross-browser library of CSS animations. As easy to use as an easy thing.

Animate.css If you need the old docs - v3.x.x and under - you can find it here. Just-add-water CSS animation Installation Install with npm: npm instal

Animate.css 76.7k Dec 30, 2022
🍿 A cross-browser library of CSS animations. As easy to use as an easy thing.

Animate.css If you need the old docs - v3.x.x and under - you can find it here. Just-add-water CSS animation Installation Install with npm: npm instal

Animate.css 76.7k Jan 4, 2023
Animation Academy teaches you CSS animations using the transition and animation properties.

Animation Academy Open Animation Academy > Contents Background Built With Functionality Feature Highlights Wireframes Features In Development Backgrou

Jacob Benowitz 6 Jun 23, 2022
fakeLoader.js is a lightweight jQuery plugin that helps you create an animated spinner with a fullscreen loading mask to simulate the page preloading effect.

What is fakeLoader.js fakeLoader.js is a lightweight jQuery plugin that helps you create an animated spinner with a fullscreen loading mask to simulat

João Pereira 721 Dec 6, 2022
fullPage plugin by Alvaro Trigo. Create full screen pages fast and simple

fullPage.js English | Español | Français | Pусский | 中文 | 한국어 Available for Vue, React and Angular. | 7Kb gziped | Created by @imac2 Demo online | Cod

Álvaro 34.3k Dec 30, 2022
Animator Core is the runtime and rendering engine for Haiku Animator and the components you create with Animator

Animator Core is the runtime and rendering engine for Haiku Animator and the components you create with Animator. This engine is a dependency for any Haiku Animator components that are run on the web.

Haiku 757 Nov 27, 2022
Create scroll-based animation without JavaScript

Trigger JS Create scroll-based animation without JavaScript. Sometimes we want to update the CSS style of an HTML element based on the scroll position

Trigger JS 1.1k Jan 4, 2023
Simple & lightweight (<4kb gzipped) vanilla JavaScript library to create smooth & beautiful animations when you scroll.

lax.js Simple & lightweight (<4kb gzipped) vanilla JavaScript library to create smooth & beautiful animations when you scroll. >> DEMO << What's new w

Alex Fox 9.4k Dec 29, 2022
A jquery plugin for CSS3 text animations.

Textillate.js v0.4.1 See a live demo here. Textillate.js combines some awesome libraries to provide an easy-to-use plugin for applying CSS3 animations

Jordan Schroter 3.6k Jan 2, 2023
CSS3 Animations with special effects

?? magic CSS3 Animations with special effects. (→ 3.1 kB gzip) Demo Checkout the demo for the animations here Table of Contents Installation Getting S

Christian 7.9k Dec 30, 2022
Chakra UI Animations is a dependancy which offers you pre-built animations for your Chakra UI components.

Chakra UI Animations Chakra UI Animations is a dependancy which offers you pre-built animations for your Chakra UI components. Installation yarn add @

Code Chemistry Inc. 9 Nov 19, 2022
A collection of CSS3 powered hover effects to be applied to links, buttons, logos, SVG, featured images and so on

A collection of CSS3 powered hover effects to be applied to links, buttons, logos, SVG, featured images and so on. Easily apply to your own elements, modify or just use for inspiration. Available in CSS, Sass, and LESS.

Ian Lunn 27.9k Jan 4, 2023
:black_medium_small_square:React Move | Beautiful, data-driven animations for React

React-Move Beautiful, data-driven animations for React. Just 3.5kb (gzipped)! Documentation and Examples Features Animate HTML, SVG & React-Native Fin

Steve Hall 6.5k Jan 1, 2023
Nebula is a lightweight (1kb compressed) JavaScript library that creates beautiful universe animations.

Nebula is a lightweight JavaScript library for creating beautiful universe animations. Including configurable Stars, Nebulas, Comets, Planets and Suns. Compatible with SSR

Florian DE LA COMBLE 34 Nov 25, 2022