-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
33 lines (28 loc) · 857 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
var hasAnimations = require('has-css-animations')
, classes = require('classes')
, cssEvent = require('css-emitter')
, once = require('once');
// API:
// animate(el, 'fadeOutRight', function(el){
// $(el).remove();
// });
// If animations aren't supported, call back immediately,
// which allows us to immediately remove specific elements.
// One issue: If the browser supports animations, but an
// animation is called that doens't exist, things get
// screwed up because the callback is never invoked.
// Workarounds? Or maybe people should just fix their css...
module.exports = animate;
function animate(el, className, fn){
if (!hasAnimations) {
if (fn) fn(el);
return;
}
var cls = classes(el);
cls.add(className);
cssEvent(el).bind(once(cleanup));
function cleanup(){
cls.remove(className);
if (fn) fn(el);
}
}