Top Related Projects
GSAP (GreenSock Animation Platform), a JavaScript animation library for the modern web
JavaScript animation engine
Set of enhancements for input control
Animate on scroll library
Parallax Engine that reacts to the orientation of a smart device
The javascript library for magical scroll interactions.
Quick Overview
Choreographer-js is a lightweight JavaScript library for creating scroll-based animations and interactions on web pages. It allows developers to easily define and control animations triggered by scroll events, enhancing the user experience with smooth and dynamic content transitions.
Pros
- Simple and intuitive API for creating scroll-based animations
- Lightweight and dependency-free, making it easy to integrate into existing projects
- Supports both vertical and horizontal scrolling animations
- Offers fine-grained control over animation timing and easing functions
Cons
- Limited documentation and examples compared to more established animation libraries
- May require additional effort for complex, multi-element animations
- Not actively maintained, with the last update being several years ago
- Lacks built-in support for more advanced features like parallax effects or 3D transformations
Code Examples
- Basic scroll animation:
var choreographer = new Choreographer({
animations: [
{
range: [-1, 1000],
selector: '#myElement',
type: 'scale',
style: 'opacity',
from: 0,
to: 1
}
]
});
This code creates a simple fade-in animation for an element with the ID 'myElement' as the user scrolls from 0 to 1000 pixels.
- Multiple animations on a single element:
var choreographer = new Choreographer({
animations: [
{
range: [0, 500],
selector: '.animated-box',
type: 'scale',
style: 'transform:translateY',
from: 0,
to: 100,
unit: 'px'
},
{
range: [0, 500],
selector: '.animated-box',
type: 'scale',
style: 'opacity',
from: 0,
to: 1
}
]
});
This example combines a vertical translation and opacity change for elements with the class 'animated-box' as the user scrolls from 0 to 500 pixels.
- Using custom easing functions:
var choreographer = new Choreographer({
animations: [
{
range: [0, 1000],
selector: '#bouncy-element',
type: 'change',
style: 'transform:translateY',
from: 0,
to: 200,
unit: 'px',
easing: function(t) {
return --t * t * t + 1;
}
}
]
});
This code applies a custom easing function to create a bouncy effect for the vertical translation of an element with the ID 'bouncy-element'.
Getting Started
-
Include the Choreographer.js file in your HTML:
<script src="path/to/choreographer.min.js"></script>
-
Create a new Choreographer instance and define your animations:
var choreographer = new Choreographer({ animations: [ { range: [0, 1000], selector: '.my-animated-element', type: 'scale', style: 'opacity', from: 0, to: 1 } ] });
-
Initialize the choreographer:
choreographer.init();
Competitor Comparisons
GSAP (GreenSock Animation Platform), a JavaScript animation library for the modern web
Pros of GSAP
- More comprehensive animation capabilities, including complex timelines and advanced easing functions
- Larger community and ecosystem, with extensive documentation and plugins
- Cross-browser compatibility and optimized performance
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 use cases
Code Comparison
Choreographer-js:
var choreographer = new Choreographer({
animations: [
{
range: [-1, 1000],
selector: '#myElement',
type: 'scale',
style: 'opacity',
from: 0,
to: 1
}
]
});
GSAP:
gsap.to("#myElement", {
duration: 1,
opacity: 1,
scale: 1,
scrollTrigger: {
trigger: "#myElement",
start: "top bottom",
end: "bottom top",
scrub: true
}
});
Both libraries offer scroll-based animations, but GSAP provides more flexibility and control over the animation process. Choreographer-js has a simpler API for basic scroll animations, while GSAP offers a more powerful and versatile solution for complex animations and interactions.
JavaScript animation engine
Pros of Anime
- More comprehensive animation library with a wider range of features
- Better performance for complex animations
- Larger community and more frequent updates
Cons of Anime
- Steeper learning curve due to more complex API
- Larger file size, which may impact page load times
Code Comparison
Choreographer-js:
var choreographer = new Choreographer({
animations: [
{
range: [-1, 1],
selector: '#box',
type: 'scale',
style: 'transform',
from: 1,
to: 2
}
]
});
Anime:
anime({
targets: '#box',
scale: [1, 2],
duration: 1000,
easing: 'easeInOutQuad'
});
Summary
Anime offers a more powerful and flexible animation solution with better performance for complex animations. It has a larger community and more frequent updates. However, it comes with a steeper learning curve and a larger file size compared to Choreographer-js.
Choreographer-js provides a simpler API and smaller file size, making it easier to learn and implement for basic animations. However, it may lack some advanced features and performance optimizations found in Anime.
The code comparison shows that Anime's syntax is more concise and intuitive for simple animations, while Choreographer-js requires more verbose configuration.
Set of enhancements for input control
Pros of react-input-enhancements
- Specifically designed for React applications, providing seamless integration
- Offers a wide range of input enhancements, including autocompletion and dropdown functionality
- Actively maintained with regular updates and bug fixes
Cons of react-input-enhancements
- Limited to React applications, unlike the more versatile Choreographer-js
- May have a steeper learning curve for developers not familiar with React
- Potentially heavier in terms of bundle size due to its React-specific features
Code Comparison
react-input-enhancements:
import { Autocomplete } from 'react-input-enhancements';
<Autocomplete
options={['Apple', 'Banana', 'Cherry']}
value={this.state.value}
onChange={value => this.setState({ value })}
/>
Choreographer-js:
var choreographer = new Choreographer({
animations: [
{
range: [-1, 1],
selector: '#myElement',
type: 'scale',
style: 'transform',
from: 0.5,
to: 1.5
}
]
});
While react-input-enhancements focuses on enhancing input fields in React applications, Choreographer-js is a more general-purpose animation library. The code examples highlight their different use cases and implementation approaches.
Animate on scroll library
Pros of AOS
- Simpler setup and usage, with predefined animations and data attributes
- Extensive documentation and examples
- Larger community and more frequent updates
Cons of AOS
- Less flexibility for custom animations
- Heavier file size compared to Choreographer.js
- Potential performance issues with many animated elements
Code Comparison
Choreographer.js:
var choreographer = new Choreographer({
animations: [
{
range: [-1, 1000],
selector: '#myElement',
type: 'scale',
style: 'opacity',
from: 0,
to: 1
}
]
});
AOS:
<div data-aos="fade-up" data-aos-duration="1000">
Animate me!
</div>
AOS.init();
Choreographer.js offers more programmatic control over animations, allowing for complex, custom animations. AOS, on the other hand, provides a simpler, more declarative approach using data attributes, making it easier to implement basic animations quickly.
Choreographer.js is lightweight and focused on scroll-based animations, while AOS includes a variety of predefined animations and options. This makes AOS more suitable for projects requiring quick implementation of common animation effects, whereas Choreographer.js is better for projects needing fine-grained control over animation behavior.
Parallax Engine that reacts to the orientation of a smart device
Pros of Parallax
- More comprehensive and feature-rich, offering a wider range of parallax effects
- Better documentation and examples, making it easier for developers to implement
- Larger community and more frequent updates, ensuring better long-term support
Cons of Parallax
- Heavier library size, which may impact page load times
- Steeper learning curve due to more complex API and configuration options
- Less flexibility for custom animations compared to Choreographer's timeline-based approach
Code Comparison
Parallax:
var scene = document.getElementById('scene');
var parallaxInstance = new Parallax(scene, {
relativeInput: true,
clipRelativeInput: false
});
Choreographer:
var choreographer = new Choreographer({
animations: [
{
range: [-1, 1000],
selector: '#myElement',
type: 'scale',
style: 'opacity',
from: 0,
to: 1
}
]
});
Both libraries offer ways to create engaging animations, but Parallax focuses on depth and motion effects, while Choreographer provides more control over timeline-based animations. Parallax is better suited for quick implementation of parallax scrolling, while Choreographer offers more flexibility for custom animation sequences.
The javascript library for magical scroll interactions.
Pros of ScrollMagic
- More comprehensive and feature-rich, offering advanced animation capabilities
- Better documentation and larger community support
- Supports both scroll-based and timeline-based animations
Cons of ScrollMagic
- Larger file size and potentially heavier on performance
- Steeper learning curve due to more complex API
- Requires additional plugins for some advanced features
Code Comparison
ScrollMagic:
var controller = new ScrollMagic.Controller();
var scene = new ScrollMagic.Scene({
triggerElement: "#trigger",
duration: 300
})
.setTween("#animate", {scale: 2.5})
.addTo(controller);
Choreographer-js:
var choreographer = new Choreographer({
animations: [
{
range: [-1, 1000],
selector: '#animate',
type: 'scale',
style: 'transform',
from: 1,
to: 2.5
}
]
});
ScrollMagic offers more control over scene creation and animation triggering, while Choreographer-js provides a simpler, more declarative approach to defining animations. ScrollMagic's syntax is more verbose but allows for greater flexibility in creating complex scroll-based animations. Choreographer-js focuses on simplicity and ease of use, making it more accessible for basic animation needs.
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
Choreographer-js
A simple library to take care of complex CSS animations.
(You can also add custom functions that do non-CSS animations!)
Other examples:
Basic Example (animating based on scroll location)
Basic Example (animating based on mouse X location)
Basic Example (multiple animations based on mouse X location)
Table of Contents + Useful Links
Quickstart
Install and save to your package.json
:
$ npm install --save choreographer-js
Include it in your Javascript:
const Choreographer = require('choreographer-js')
Use Cases + Snippets
Brew up some instant scroll animations. This one would scale a box's opacity
from 0
to 1
mirroring your scroll location from the top to 1000
. Full Example >>
let choreographer = new Choreographer({
animations: [
{
range: [-1, 1000],
selector: '#box',
type: 'scale',
style: 'opacity',
from: 0,
to: 1
}
]
})
window.addEventListener('scroll', () => {
choreographer.runAnimationsAt(window.pageYOffset)
})
What about animations based on mouse movement? This would make #box
move 300px
down if your mouse was in the left-half of the browser window.
let choreographer = new Choreographer({
animations: [
{
range: [-1, window.innerWidth / 2],
selector: '#box',
type: 'change',
style: 'transform:translateY',
to: 300,
unit: 'px'
}
]
})
document.body.addEventListener('mousemove', (e) => {
choreographer.runAnimationsAt(e.clientX)
})
Get Started
You can simply install the package via npm:
$ npm install --save choreographer-js
Or if you're keeping things super simple, just include this file as a script like so:
<script src="your_path/choreographer.min.js"></script>
Cool! Now you can create an instance of Choreographer like this, and run the animations based on whatever measurement floats your boat (ex. scroll position, mouse position, timestamp, whatever).
let choreographer = new Choreographer(config)
choreographer.runAnimationsAt(position)
More often than not, you'll probably want to wrap that runAnimationsAt
function in another, like an event handler, for instance:
window.addEventListener('scroll', () => {
// then, use the scroll position (pageYOffset) to base the animations off of
choreographer.runAnimationsAt(window.pageYOffset)
})
The easiest way to understand how this all works is to check out the examples. More detailed documentation below!
Full API Reference
Choreographer
[Class]
| The home base for everything.
construction:
new Choreographer(
choreographerConfig
)
public methods:
choreographerConfig
[Object]
| The object used to configure an instance of Choreographer.
example structure:
{
customFunctions: {
[animation type]: [animationFunction]
},
animations: [ animationConfig, animationConfig, ... ]
}
related references: animationFunction
, animationConfig
Choreographer.updateAnimations([ Array of
animationConfig
])
[Function]
| Replace this.animations
with a new Array of Animations
.
Choreographer.runAnimationsAt([ Number ])
[Function]
| Run the animations at a given location marker.
Animation
[Class]
| The class that manages each animation's data.
construction:
new Animation(
animationConfig
)
animationConfig
[Object]
| The object used to configure an instance of Animation.
example structure:
{
range: [0, 100],
selector: '.box',
type: 'scale',
fn: [animationFunction],
style: 'width',
from: 0,
to: 100,
unit: '%'
}
range
| [Array of Number]
or [Array of Array of Number]
Either a one- or two-dimensional array of ranges, i.e. [0,5] or [[0,3], [4,5]]
NOTE: Bugs will occur if you overlap animation ranges that affect the same style properties!
type
| [String]
The name of the animation function
fn
| [animationFunction]
see animationFunction
](#animationfunction)
selector
| [String]
or [NodeList]
or [DOM Element]
A valid DOM Element, list of elements, or selector string, ex. '.classname' or '#box .thing[data-attr=true]'
selectors
| [Array]
An array of selector strings (as described above).
NOTE: Only one of the below (selector or selectors) is necessary. If they both exist, 'selectors' will be used.
style
| [String]
A valid CSS style property OR the string "class" to toggle a classname instead.
NOTE: If you are using 'transform', follow it with a colon and the property name, ex. 'transform:scaleX'
from
| [Number]
The minimum value to set to the style property. Useful when progressively calculating a value.
to
| [Number or String]
If you want progressively calculated (scaled) values, this has to be a number. Otherwise, if for something a 'change' animation, this can be a string - whatever the valid type for the relevant style
property is.
related references: animationFunction
animationFunction
[Function]
| A function that takes animationData
and does something with it.
There are two built-in animation functions available, called 'scale' and 'change'.
- 'scale' maps a progressively calculated value to the node's style property based on location
- 'change' adds or takes away a style property value if you're in or out of range
Example animationFunction (this is a simplified version of how 'change' works):
(data) => {
// where data is an 'animationData' object (see below)
const newValueString = data.to + data.unit
if (data.progress > 0 && data.progress < 1) {
data.node.style[data.style] = newValueString
}
}
arguments: animationData
animationData
[Object]
| This is the data passed into an animationFunction
. A lot of it is taken directly from animationConfig
.
Structure:
{
node: [DOM Element] | the element this animation will affect,
progress: [Number] | a number representing the relative location of a node within a range,
// these are all taken directly from the animationConfig
style: (see above),
from: (see above),
to: (see above),
unit: (see above),
}
Progress
is what allows for progressive scaling of values (ex. smooth fading of opacity, 2d translation, etc.)
If the value is between 0 and 1, that means you are within a range (given in animationConfig).
Contributing
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
Found an issue but don't know how to fix it? Submit an issue or email me.
License
The MIT License (MIT) Copyright (c) 2016 Christine Cha
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Top Related Projects
GSAP (GreenSock Animation Platform), a JavaScript animation library for the modern web
JavaScript animation engine
Set of enhancements for input control
Animate on scroll library
Parallax Engine that reacts to the orientation of a smart device
The javascript library for magical scroll interactions.
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