-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.shunt.js
69 lines (51 loc) · 1.75 KB
/
jquery.shunt.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*
shunt - https://github.com/reconstrukt/shunt
A jquery plugin for css3 animation chaining.
by Matthew Knight, http://reconstrukt.com
Licensed under the MIT license.
*/
(function(jQuery){
jQuery.fn.shunt = function(animation, duration, start, cb) {
// shorthand call style
if (jQuery.isFunction(duration)) {
cb = duration;
duration = 1000;
start = 0;
}
if (jQuery.isFunction(start)) {
cb = start;
start = 0;
}
if (typeof duration !== 'number') duration = 1000;
if (typeof start !== 'number') start = 0;
var uid = 'shunt-' + (new Date().getTime()) + '-' + (Math.floor( Math.random()*1000000 ));
var classes = [uid, 'animated ' + animation];
var prefixes = ['webkit-', 'moz-', 'ms-', 'o-', ''];
var endevent = 'animationend webkitAnimationEnd oAnimationEnd';
var ttl = duration / 1000 + 's';
var delay = start / 1000 + 's';
var animcss = [];
for (var i in prefixes) {
var dur = prefixes[i] + 'animation-duration';
var del = prefixes[i] + 'animation-delay';
animcss.push(dur);
animcss.push(del);
this.css(dur, ttl).css(del, delay);
}
this
.addClass(classes.join(' '))
.attr('data-shunt-classes', classes.join(' '))
.attr('data-shunt-animcss', animcss.join(','))
.one(endevent, function(){
var source = jQuery('.' + uid);
var classes = source.attr('data-shunt-classes');
source.removeClass(classes);
var animcss = source.attr('data-shunt-animcss').split(',');
for (i=0; i < animcss.length; i++) source.css(animcss[i], '');
source
.removeAttr('data-shunt-classes')
.removeAttr('data-shunt-animcss');
if (jQuery.isFunction(cb)) jQuery(this).each(cb);
});
};
})(jQuery);