Skip to content
An utility to know when your CSS transitions end
JavaScript
Find file
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
dist Release 0.2.3
lib refactor(trigger): enable usage of a variable or function for trigger
tasks style(tasks): fix remaining style issue
.editorconfig chore(setup): generate project from generator-jslib
.gitignore chore(setup): generate project from generator-jslib
.jscs.json chore(setup): generate project from generator-jslib
.jshintrc
.travis.yml chore(setup): generate project from generator-jslib
Gruntfile.js chore(setup): generate project from generator-jslib
LICENSE chore(LICENSE): add MIT short license
README.md doc(README): add timing issue section
bower.json Release 0.2.3
package.json

README.md

motioncontrol.js

Build Status

An utility to know when your CSS transitions has ended, based on Promise with a fallback with timeout.

Installation

$ npm install --save motioncontrol.js
$ bower install --save motioncontrol.js

Usage

CommonJS

var motioncontrol = require('motioncontrol');
motioncontrol(el, options).then(function () {
  // do something
});

AMD

define(['motioncontrol', function (motioncontrol) {

  motioncontrol(el, options).then(function () {
    // do something
  });
});

Options

trigger

Type: function Default: undefined

This function, if provided, will be called. This should be used if you need a callback to start the animation.

timeout

Type: integer Default: 1000

It's the number of milliseconds before the timout will be fired. Internally it will call the transitionend event listener

Documentation

The idea of this library is to have a promise that tells you when a CSS animation has ended. It uses the native promise or any implementation you provide which means that you should be able to use this microlib everywhere.

var motioncontrol = require('motioncontrol');
var Promise = require('bluebird'); // or Q, when, RSVP, jarchibal polyfill ...

// add the promise constructor to the motioncontrol instance
motioncontrol.Promise = Promise;

motioncontrol(el, {/* options */});

Timing issue

While this library support animation end with a fallback to timeout your code should not be in a forever waiting state. But on the other end, you should pay a little attention about timing issue. If your animation time is longer than the default timeout or any value you provide, the result won't be the one expected. The consequence might vary from undetected to bad user experience. What I mean is that if your promise resolution is used to destroy an animated view, and the timeout fired before the animation has been completed, the user will seen an interrupted animation. It should only be unpleasant. But it could also lead to runtime error depending on what you do in the promise resolution.

License

Copyright (c) 2014 Stéphane Bachelier - MIT

Something went wrong with that request. Please try again.