Skip to content

Commit

Permalink
doco
Browse files Browse the repository at this point in the history
  • Loading branch information
James Newell committed May 20, 2015
1 parent 6a651f4 commit 78d67e5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 15 deletions.
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# animation-events

Bind and unbind animation events.

## Installation

Component:
Expand Down Expand Up @@ -29,12 +31,24 @@ Component:

#### .supported

Get whether animations are supported by the browser.

#### .has(el)

Get whether an element has an animation applied.

#### .bind(el, event, callback)

Add a callback for an animation event (`start`, `end` or `iteration`).

#### .unbind(el, event, callback)

Remove a callback for an animation event (`start`, `end` or `iteration`).

#### .once(el, event, callback)

Add a callback for a single animation event (`start`, `end` or `iteration`).

## Building

browserify index.js -r ./index.js:animation-events > build/build.js
Expand Down
30 changes: 15 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function style(el) {
module.exports = {

/**
* Whether animations are supported by the browser
* Get whether animations are supported by the browser
* @type {boolean}
*/
supported: !!prop,
Expand All @@ -73,20 +73,6 @@ module.exports = {
return cs[prop].length > 0 && cs[prop] !== '0s';
},

/**
* Add a callback for a single animation event
* @param {HTMLElement} el The element
* @param {string} event The event - `start`, `end` or `iteration`
* @param {function} callback The callback
*/
once: function(el, event, callback) {
var self = this;
return this.bind(el, event, function fn() {
callback.apply(el, arguments);
self.unbind(el, event, fn);
});
},

/**
* Add a callback for an animation event
* @param {HTMLElement} el The element
Expand Down Expand Up @@ -125,6 +111,20 @@ module.exports = {

el.removeEventListener(event, callback);
return this;
},

/**
* Add a callback for a single animation event
* @param {HTMLElement} el The element
* @param {string} event The event - `start`, `end` or `iteration`
* @param {function} callback The callback
*/
once: function(el, event, callback) {
var self = this;
return this.bind(el, event, function fn() {
callback.apply(el, arguments);
self.unbind(el, event, fn);
});
}

};

0 comments on commit 78d67e5

Please sign in to comment.