• Stars
    star
    197
  • Rank 191,828 (Top 4 %)
  • Language
    JavaScript
  • Created about 6 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸ”₯ Create timeline and playback based animations in React

Animated Timeline

author size Build Status

Create playback based animations in React

Table of contents

Introduction

animated-timeline is an animation library (not really) for React which makes it painless to create playback based animations.

Another animation library ?

Nope! Though you can use it as a library. The main goal of this project is to provide -

  • utilities to create animation tools

  • low-level APIs to create a fitting abstraction on top of this project

  • APIs for composing animations that transition from one state to another, use loops, callbacks and timer APIs to create interactive animations

Concepts

animated-timeline works on two models, timing and animation model.

Timing model

Timing model manages the time and keeps track of current progress in a timeline.

Animation model

Animation model, on the other hand, describes how an animation could look like at any give time or it can be thought of as state of an animation at a particular point of time.

Using both the models, we can synchronize the timing and visual changes to the document.

Features

  • Controls for time-based execution of an animation

  • Create sequence based animations

  • Timing based animations

  • Change the animation position along the timeline by seeking the animation

  • Keyframes

  • Promise based APIs

  • Interactive animations based on changing inputs

  • Spring physics and bounciness

Performance

Style mutations and style reads are batched internally to speed up the performance and avoid document reflows.

Install

npm install animated-timeline

or if you use yarn

yarn add animated-timeline

This project also depends on react and react-dom so make sure you've them installed.

Browser support

Chrome Safari IE / EDGE Firefox Opera
24+ 6+ 10+ 32+ 15+

Usage

animated-timeline provides three ways to do animations:

Example usage with component API

import React from 'react'
import { Animate, helpers } from 'animated-timeline'

const styles = {
  width: '20px',
  height: '20px',
  backgroundColor: 'pink'
}

// Properties for timing model
const timingProps = {
  duration: 1000
}

// Properties for animation model
const animationProps = {
  rotate: helpers.transition({ from: 360, to: 180 })
}

function App() {
  return (
    <Animate timingProps={timingProps} animationProps={animationProps}>
      <div style={styles} />
    </Animate>
  )
}

Read the detailed API reference for Component API

Example usage with Timeline API

import React from 'react'
import { createTimeline, helpers } from 'animated-timeline'

const styles = {
  width: '20px',
  height: '20px',
  backgroundColor: 'pink'
}

const t = createTimeline({
  direction: 'alternate',
  iterations: 1
})

class App extends React.Component {
  componentDidMount() {
    t
      .animate({
        opacity: helpers.transition({ from: 0.2, to: 0.8 }),
        rotate: helpers.transition({ from: 360, to: 180 })
      })
      .start()
  }

  render() {
    return <t.div style={styles} />
  }
}

Read the detailed API reference for Timeline API

Example usage with spring physics

import React from 'react'

import { Spring } from 'animated-timeline'

const styles = {
  width: '20px',
  height: '20px',
  backgroundColor: 'pink'
}

const s = Spring({ friction: 4, tension: 2 })

// or

// const s = Spring({ bounciness: 14, speed: 12 })

class SpringSystem extends React.Component {
  componentDidMount() {
    s.animate({
      property: 'scale',
      map: {
        inputRange: [0, 1],
        outputRange: [1, 1.5]
      }
    })
  }

  render() {
    return (
      <s.div
        onMouseUp={() => s.setValue(0)}
        onMouseDown={() => s.setValue(1)}
        style={styles}
      />
    )
  }
}

Read the detailed API reference for spring physics

Animation types

Sequence based animations

Edit 6j08xylw7n

Timing based animations

Edit 92lm0xrl44

Staggered animation

Edit 743n1z9826

Keyframes

Edit 92lm0xrl44

Changing the animation position

You can also change the animation position along its timeline with an input value.

Edit kkjn9jq6k7

Spring based animations

Edit 75l1z6jzq

More examples

Animation values

  • For transforms
t.animate({
  scale: 1,
  rotateX: '360deg' // with or without unit
})
  • For css properties
t.animate({
  width: '20px'
})
  • Defining values using objects
t.animate({
  rotate: {
    value: 360, // 360deg
    duration: 3000,
    delay: 200,
    direction: 'alternate'
  }
})

Check out this list to see which properties you can use when defining the animation values using objects.

  • from - to based animation values
import { helpers } from 'animated-timeline'

t.animate({
  scale: helpers.transition({ from: 2, to: 1 })
})

Read more about helpers object here.

  • Timing based animation values

Use property offset to perform timing animations

import { helpers } from 'animated-timeline'

t
  .sequence([
    t.animate({
      el: '.one',
      scale: 2
    }),

    t.animate({ el: '.two', scale: 1, offset: helpers.startAfter(2000) })
  ])
  .start()

You can set a value for a property with or without any unit such as px, em, rem, in, cm, mm, vw, vh, vmin, vmax, deg, rad, turn etc.

Documentation

Check out the detailed documentation for animated-timeline.

Todos

  • ReasonML port of the core engine

  • timing model based on scroll position and gestures ?

  • Synchronize engine time with speed coefficient

  • Refactor tween data structure for more flexibility

  • Use data binding

More Repositories

1

react-perf-devtool

A browser developer tool extension to inspect performance of React components.
JavaScript
2,324
star
2

react-imgpro

πŸ“· Image Processing Component for React
JavaScript
2,176
star
3

terminal-in-react

πŸ‘¨β€πŸ’» A component that renders a terminal
JavaScript
2,120
star
4

redocx

πŸ“„ Create word documents with React
JavaScript
1,389
star
5

Making-a-custom-React-renderer

Tutorial on how to make a custom React renderer
JavaScript
1,286
star
6

animate-components

✨ Elemental components for doing animations in React
JavaScript
909
star
7

React-Web-AR

πŸ•ΆοΈ Augmented Reality on web with React
JavaScript
571
star
8

react-color-extractor

A React component which extracts colors from an image
JavaScript
351
star
9

Python-Automation

πŸ’» These are some projects which I worked upon to automate stuffs using python
Python
246
star
10

react-video-scroll

A React component to seek or control the video frame rate on scroll.
JavaScript
135
star
11

glamorous-primitives

πŸ’„ style primitive React interfaces with glamorous
JavaScript
92
star
12

react-tint

A React component that applies image processing filters to an image using Processing
JavaScript
87
star
13

react-color-tools

A set of tools as React components for working with colors 🎨
JavaScript
87
star
14

shaping-functions

Visualisation of shaping functions
JavaScript
75
star
15

linkify-markdown

πŸš€ A cli tool which automatically add references to issues, pull requests, user mentions and forks to a markdown file.
JavaScript
69
star
16

react-handy-renderer

✏️ Draw 2D primitives in sketchy style with React
JavaScript
61
star
17

generative-designs

A collection of generative design React components
JavaScript
58
star
18

stylus-in-react

πŸ’„ Style React components with Stylus
JavaScript
54
star
19

react-text-fun

React meets Blotter.js
JavaScript
52
star
20

react-marker

πŸ–οΈ Highlight keywords and add colors to your text.
JavaScript
47
star
21

generative-art-tools

Utilities for creating generative art
JavaScript
27
star
22

vscode-glamorous

πŸ€™ code snippets for glamorous
21
star
23

Elements-of-physics

Representing elements of physics using React
JavaScript
20
star
24

react-shader-canvas

A small utility function to render the shaders using React
JavaScript
20
star
25

Creating-a-pretty-printer

This is a tutorial for creating a pretty printer in JavaScript
JavaScript
13
star
26

generative-art-snippets

A collection of some useful snippets used in crafting computational art
10
star
27

glamorous-redocx

style redocx components with glamorous πŸ’„
JavaScript
10
star
28

Tidings

πŸ—žοΈ A NLP based news app powered by API.ai
JavaScript
8
star
29

pro-branch

A small package that provides helpers to manage control flow in React
JavaScript
8
star
30

lightup

πŸ’‘ A cli tool to quickly launch your react app in an effortless way.
JavaScript
8
star
31

glamorous-stylus

Use Stylus with glamorous
JavaScript
6
star
32

react-image-overlay-effect

A React component for displaying an overlay effect on an image.
TypeScript
5
star
33

component-dot-json

Create and mock stateless React components using JSON
JavaScript
5
star
34

Creating-a-JavaScript-UI-library

This is a tutorial for creating a JavaScript UI library.
5
star
35

babel-preset-hyperapp

A Babel preset for HyperApp
JavaScript
4
star
36

HyperApp-Examples

HyperApp examples
JavaScript
4
star
37

word-classes-visualiser

A small tool based on Compromise NLP to visualise the different word classes from English grammar.
JavaScript
4
star
38

Blog

πŸ“— My writings
3
star
39

algorithmic-art-sketchbook

work in progress
JavaScript
3
star
40

css-to-rn

Convert css string to React Native
JavaScript
3
star
41

Learning-Processing

A curated list of resources, links and books for learning processing
JavaScript
3
star
42

glam-atom

Glamorous Snippets for Atom
3
star
43

myspace

Blog
2
star
44

Working-with-APIs

This repository contains scripts for accessing the third party APIs using Python, JavaScript and Ruby.
Python
2
star
45

T-Box

A command line utility to manage the file uploads, downloads and sharing directly from terminal on your Dropbox.
JavaScript
2
star
46

Nitin-Blog

Welcome to my blog!
2
star
47

personal-blog

My blog
JavaScript
2
star
48

Resume

1
star
49

test-repo

1
star
50

test-draft-releaser

1
star
51

nextjs-netlify-blog-template

TypeScript
1
star
52

Escaper

A small library which provides methods to escape and unescape HTML entities.
JavaScript
1
star
53

nextjs-netlify-blog-template-nitin

1
star
54

insiderin-assignment

assignment
JavaScript
1
star
55

nitin42

My personal repository
1
star
56

Project-Euler

Contains my solutions to the computational problems at https://projecteuler.net/
Python
1
star
57

grabvatar

An amazing tool to generate cool avatars for your profile picture given an identifier.
JavaScript
1
star
58

Real-Markdown

An app that let’s us view the raw markdown on one side and the converted markdown (to HTML) on the other side.
JavaScript
1
star
59

routes-getter

Walks through your routes folder and imports them to your project.
JavaScript
1
star