Added callback to animation

master
Dmitry Baranovskiy 2013-08-16 12:56:19 +10:00
parent 583bb2a37d
commit f5a8d501e3
4 changed files with 44 additions and 18 deletions

12
mina.js
View File

@ -25,6 +25,11 @@ window.mina = (function () {
return a instanceof Array || return a instanceof Array ||
Object.prototype.toString.call(a) == "[object Array]"; Object.prototype.toString.call(a) == "[object Array]";
}, },
idgen = 0,
idprefix = "M" + (+new Date).toString(36),
ID = function () {
return idprefix + (idgen++).toString(36);
},
diff = function (a, b, A, B) { diff = function (a, b, A, B) {
if (isArray(a)) { if (isArray(a)) {
res = []; res = [];
@ -79,17 +84,22 @@ window.mina = (function () {
if (isArray(a.start)) { if (isArray(a.start)) {
res = []; res = [];
for (var j = 0, jj = a.start.length; j < jj; j++) { for (var j = 0, jj = a.start.length; j < jj; j++) {
res[j] = a.start[j] + (a.end[j] - a.start[j]) * a.easing(a.s); res[j] = a.start[j] +
(a.end[j] - a.start[j]) * a.easing(a.s);
} }
} else { } else {
res = a.start + (a.end - a.start) * a.easing(a.s); res = a.start + (a.end - a.start) * a.easing(a.s);
} }
a.set(res); a.set(res);
if (a.s == 1 && typeof eve != "undefined") {
eve("mina.finish." + a.id, a);
}
} }
animations.length && requestAnimFrame(frame); animations.length && requestAnimFrame(frame);
}, },
mina = function (a, A, b, B, get, set, easing) { mina = function (a, A, b, B, get, set, easing) {
var anim = { var anim = {
id: ID(),
start: a, start: a,
end: A, end: A,
b: b, b: b,

4
savage-min.js vendored

File diff suppressed because one or more lines are too long

View File

@ -428,6 +428,11 @@ window.mina = (function () {
return a instanceof Array || return a instanceof Array ||
Object.prototype.toString.call(a) == "[object Array]"; Object.prototype.toString.call(a) == "[object Array]";
}, },
idgen = 0,
idprefix = "M" + (+new Date).toString(36),
ID = function () {
return idprefix + (idgen++).toString(36);
},
diff = function (a, b, A, B) { diff = function (a, b, A, B) {
if (isArray(a)) { if (isArray(a)) {
res = []; res = [];
@ -482,17 +487,22 @@ window.mina = (function () {
if (isArray(a.start)) { if (isArray(a.start)) {
res = []; res = [];
for (var j = 0, jj = a.start.length; j < jj; j++) { for (var j = 0, jj = a.start.length; j < jj; j++) {
res[j] = a.start[j] + (a.end[j] - a.start[j]) * a.easing(a.s); res[j] = a.start[j] +
(a.end[j] - a.start[j]) * a.easing(a.s);
} }
} else { } else {
res = a.start + (a.end - a.start) * a.easing(a.s); res = a.start + (a.end - a.start) * a.easing(a.s);
} }
a.set(res); a.set(res);
if (a.s == 1 && typeof eve != "undefined") {
eve("mina.finish." + a.id, a);
}
} }
animations.length && requestAnimFrame(frame); animations.length && requestAnimFrame(frame);
}, },
mina = function (a, A, b, B, get, set, easing) { mina = function (a, A, b, B, get, set, easing) {
var anim = { var anim = {
id: ID(),
start: a, start: a,
end: A, end: A,
b: b, b: b,
@ -2463,13 +2473,16 @@ function arrayFirstValue(arr) {
tkeys = tkeys.concat(to); tkeys = tkeys.concat(to);
} }
var now = mina.time(), var now = mina.time(),
el = this; el = this,
return mina(fkeys, tkeys, now, now + ms, mina.time, function (val) { anim = mina(fkeys, tkeys, now, now + ms, mina.time, function (val) {
var attr = {}; var attr = {};
for (var key in keys) if (keys[has](key)) { for (var key in keys) if (keys[has](key)) {
attr[key] = keys[key](val); attr[key] = keys[key](val);
} }
el.attr(attr); el.attr(attr);
});
callback && eve.once("mina.finish." + anim.id, function () {
callback.call(el);
}); });
}; };
}(Element.prototype)); }(Element.prototype));

17
svg.js
View File

@ -1587,13 +1587,16 @@ function arrayFirstValue(arr) {
tkeys = tkeys.concat(to); tkeys = tkeys.concat(to);
} }
var now = mina.time(), var now = mina.time(),
el = this; el = this,
return mina(fkeys, tkeys, now, now + ms, mina.time, function (val) { anim = mina(fkeys, tkeys, now, now + ms, mina.time, function (val) {
var attr = {}; var attr = {};
for (var key in keys) if (keys[has](key)) { for (var key in keys) if (keys[has](key)) {
attr[key] = keys[key](val); attr[key] = keys[key](val);
} }
el.attr(attr); el.attr(attr);
});
callback && eve.once("mina.finish." + anim.id, function () {
callback.call(el);
}); });
}; };
}(Element.prototype)); }(Element.prototype));