weex-nuke
Version:
基于 Rax 、Weex 的高性能组件体系 ~~
100 lines (77 loc) • 2.28 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.easeOutBounce = easeOutBounce;
exports.easeInOutQuad = easeInOutQuad;
var counter = 1;
var running = {};
var Animate = exports.Animate = {
requestAnimationFrame: function () {
// isomorphic support
if (typeof window === 'undefined') {
return function () {};
}
var requestFrame = window.requestAnimationFrame || window.webkitRequestAnimationFrame;
return function (callback) {
requestFrame(callback);
};
}(),
start: function start(stepFunc, callback, duration, easeFunc) {
var max = Math.max,
min = Math.min;
var animateId = counter++;
var startTime = null,
lastTime = null;
running[animateId] = true;
var step = function step(timeStamp) {
if (running[animateId] !== true) {
return;
}
if (startTime === null) {
startTime = timeStamp;
lastTime = timeStamp;
}
var percent = 0,
timeDiff = timeStamp - startTime,
timeFrame = timeStamp - lastTime;
lastTime = timeStamp;
if (duration) {
percent = min(timeDiff / duration, 1);
}
if (percent >= 1 || running[animateId] !== true) {
stepFunc(percent, timeDiff, timeFrame);
callback();
running[animateId] = false;
delete running[animateId];
return;
}
if (easeFunc) {
percent = easeFunc(timeDiff, 0, 1, duration);
}
stepFunc(percent, timeDiff, timeFrame);
Animate.requestAnimationFrame(step);
};
Animate.requestAnimationFrame(step);
return animateId;
},
stop: function stop(animateId) {
running[animateId] = false;
delete running[animateId];
}
};
function easeOutBounce(t, b, c, d) {
if ((t /= d) < 1 / 2.75) {
return c * (7.5625 * t * t) + b;
} else if (t < 2 / 2.75) {
return c * (7.5625 * (t -= 1.5 / 2.75) * t + .75) + b;
} else if (t < 2.5 / 2.75) {
return c * (7.5625 * (t -= 2.25 / 2.75) * t + .9375) + b;
} else {
return c * (7.5625 * (t -= 2.625 / 2.75) * t + .984375) + b;
}
}
function easeInOutQuad(t, b, c, d) {
if ((t /= d / 2) < 1) return c / 2 * t * t + b;
return -c / 2 * (--t * (t - 2) - 1) + b;
}
;