0.7.33 • Published 2 years ago

rive-js v0.7.33

Weekly downloads
531
License
MIT
Repository
github
Last release
2 years ago

Rive.js -- Rive's Web API

ALPHA RELEASE!

Rive.js is fresh off the presses and in an alpha state; the api is subject to change as we try to make it fit for purpose. Please file issues and PRs for anything busted, missing, or just plain wrong.

Installing

The simplest way to get this running is copy src/rive.js into your project.

Quick Start

Play the first animation in the default artboard:

<canvas id="canvas"></canvas>
<script src="https://unpkg.com/rive-js/rive.js"></script>
<script>
    // autoplays the first animation in the default artboard
    new RiveAnimation({
        src: 'https://cdn.rive.app/animations/off_road_car_blog_0_6.riv',
        canvas: document.getElementById('canvas'),
        autoplay: true,
    });
</script>

Playing and Mixing Animations

Rive.js requires two things: a link to the Rive file, and a canvas element where the animation should be rendered. Setting autoplay: true will play a one-shot animation once, or a looping animation continuously.

If you want to specify which artboard or animation to play:

new RiveAnimation({
    src: 'https://cdn.rive.app/animations/off_road_car_blog_0_6.riv',
    canvas: document.getElementById('canvas'),
    artboard: 'New Artboard',
    animations: 'idle',
    autoplay: true,
});

animations can also take a list of animations, which will be mixed together:

new RiveAnimation({
    src: 'https://cdn.rive.app/animations/off_road_car_blog_0_6.riv',
    canvas: document.getElementById('canvas'),
    animations: ['idle', 'windshield_wipers', 'bouncing'],
    autoplay: true,
});

You can manually start and pause playback, and check if playback is active:

const animation = new RiveAnimation({
    src: 'https://cdn.rive.app/animations/off_road_car_blog_0_6.riv',
    canvas: document.getElementById('canvas'),
});

animation.play();
animation.pause();
animation.isPlaying();

If Rive data's being loaded by other means, you can pass in an ArrayBuffer:

const reader = new FileReader();
reader.onload = function() {
    const riveArrayBuffer = reader.result;
    new RiveAnimation({
        buffer: riveArrayBuffer,
        canvas: document.getElementById('canvas'),
    });
};
reader.readAsArrayBuffer(file);

Events

Rive.js has a number of events that you can listen for:

const animation = new RiveAnimation({
    src: 'https://cdn.rive.app/animations/off_road_car_blog_0_6.riv',
    canvas: document.getElementById('canvas'),
});

// See what animations are on the artboard once the Rive file loads
animation.on('load', function() {
    console.log('Animations ' + animation.animationNames());
});

// onloop will pass the name of the looped animation and loop type; useful when mixing multiple animations together
animation.on('loop', function(event) {
    console.log(event.animationName + ' has looped as a ' + event.loopName);
});

Event callbacks currently supported are:

  • onload: fired when the Rive file is loaded and ready for playback
  • onloaderror: fired if an error occurred while trying to load a Rive file
  • onplay: Rive has started playing an animation
  • onpause: playback has been paused
  • onloop: one of the playing animations has looped (LoopEvent)
  • onstop: playback has stopped (when the animation completes if not a looping animation)

Other Functions

  • source(): returns the source for the animation
  • animationNames(): returns a list of animations on the chosen (or default) artboard

Examples

To run the examples in the examples folder, run a HTTP server at the root of the js directory. If you have Python installed, the following works nicely:

python3 -m http.server 8000

or Node:

npx http-server

and then navigate to the examples, e.g.: http://localhost:8000/examples/hello_world/index.html.

1.0.1

2 years ago

1.0.0

2 years ago

0.8.0-test

2 years ago

0.8.0-alpha

2 years ago

0.8.1

2 years ago

0.7.33

2 years ago

0.7.32

3 years ago

0.7.31

3 years ago

0.7.30

3 years ago

0.7.29

3 years ago

0.7.28

3 years ago

0.7.27

3 years ago

0.7.26

3 years ago

0.7.24

3 years ago

0.7.25

3 years ago

0.7.22

3 years ago

0.7.23

3 years ago

0.7.21

3 years ago

0.7.20

3 years ago

0.7.19

3 years ago

0.7.18

3 years ago

0.7.17

3 years ago

0.7.16

3 years ago

0.7.15

3 years ago

0.7.14

3 years ago

0.7.8-beta.7

3 years ago

0.7.8-beta.9

3 years ago

0.7.8-beta.8

3 years ago

0.7.11

3 years ago

0.7.10

3 years ago

0.7.9

3 years ago

0.7.13

3 years ago

0.7.12

3 years ago

0.7.8

3 years ago

0.7.8-beta.6

3 years ago

0.7.8-beta.5

3 years ago

0.7.8-beta.4

3 years ago

0.7.8-beta.3

3 years ago

0.7.8-beta.2

3 years ago

0.7.8-beta.1

3 years ago

0.7.6

3 years ago

0.7.7

3 years ago

0.7.5

3 years ago

0.7.4

3 years ago

0.6.1-alpha.1

3 years ago

0.6.2-beta.1

3 years ago

0.7.3

3 years ago

0.7.2

3 years ago

0.7.1

3 years ago

0.6.1

3 years ago

0.7.0

3 years ago

0.6.0

3 years ago

0.1.0-beta.4

3 years ago

0.1.0-beta.3

3 years ago

0.1.0-beta.2

3 years ago

0.1.0-beta.1

3 years ago

0.0.3

3 years ago

0.0.4

3 years ago

0.0.2

3 years ago

0.0.1-alpha.12

3 years ago

0.0.1-alpha.11

3 years ago

0.0.1-alpha.13

3 years ago

0.0.1-alpha.10

3 years ago

0.0.1-alpha.9

3 years ago

0.0.1-alpha.6

3 years ago

0.0.1-alpha.7

3 years ago

0.0.1-alpha.8

3 years ago

0.0.1-alpha.5

3 years ago

0.0.1-alpha.4

3 years ago

0.0.1-alpha.3

3 years ago

0.0.1-alpha.2

3 years ago

0.0.1-alpha.1

3 years ago

0.0.1-alpha.0

3 years ago