forked from mattdesl/gsap-promise
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
47 lines (41 loc) · 1.26 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
var assign = require('object-assign');
module.exports = function(Promise, TweenModule) {
function animateFunc(func, element, duration, opts) {
opts = assign({}, opts);
var tween;
return new Promise(function(resolve, reject, onCancel) {
opts.onComplete = resolve;
tween = func(element, duration, opts);
onCancel &&
onCancel(function() {
tween.kill();
});
});
}
var animateTo = animateFunc.bind(null, TweenModule.to);
var util = animateTo;
util.to = animateTo;
util.from = animateFunc.bind(null, TweenModule.from);
util.set = function animateSet(element, params) {
params = assign({}, params);
return new Promise(function(resolve, reject) {
params.onComplete = resolve;
TweenModule.set(element, params);
});
};
util.fromTo = function animateFromTo(element, duration, from, to) {
to = assign({}, to);
var tween;
return new Promise(function(resolve, reject, onCancel) {
to.onComplete = resolve;
tween = TweenModule.fromTo(element, duration, from, to);
onCancel &&
onCancel(function() {
tween.kill();
});
});
};
util.killTweensOf = TweenModule.killTweensOf.bind(TweenModule);
util.all = Promise.all;
return util;
};