File: src/Helpers/ease.js
/**
Easing functions for various usage
var coord = window.ease.sineOut(time, 0, 1);
myDom.style.left = 500 * coord + "px";
@method ease
@for window
@param {Number} t The time value while being eased
@param {Number} c The start value to be eased from
@param {Number} b The destination value to ease
@return {Number} Result value
**/
window.ease = (function() {
var PI = Math.PI, PIH = PI * 0.5;
return {
linear: function(t, c, b) {
return b * t + c;
},
backIn: function(t, c, b) {
return b * t * t * (2.70158 * t - 1.70158) + c;
},
backOut: function(t, c, b) {
t -= 1;
return b * ( t * t * (2.70158 * t + 1.70158) + 1) + c;
},
backInOut: function(t, c, b) {
t *= 2;
if (t < 1) {
return 0.5 * b * t * t * (3.5949095 * t - 2.5949095) + c;
} else {
t -= 2;
return 0.5 * b * (t * t * (3.70158 * t + 2.70158) + 2) + c;
}
},
bounceOut: function(t, c, b) {
if (t < 0.363636) {
return 7.5625 * b * t * t + c;
} else if (t < 0.727272) {
t -= 0.545454;
return b * (7.5625 * t * t + 0.75) + c;
} else if (t < 0.90909) {
t -= 0.818181;
return b * (7.5625 * t * t + 0.9375) + c;
} else {
t -= 0.95454;
return b * (7.5625 * t * t + 0.984375) + c;
}
},
sineIn: function(t, c, b) {
return -b * Math.cos(t * PIH) + b + c;
},
sineOut: function(t, c, b) {
return b * Math.sin(t * PIH) + c;
},
sineInOut: function(t, c, b) {
return 0.5 * -b * (Math.cos(PI * t) - 1) + c;
},
circleIn: function(t, c, b) {
return -b * (Math.sqrt(1 - t * t) - 1) + c;
},
circleOut: function(t, c, b) {
t -= 1;
return b * Math.sqrt(1 - t * t) + c;
},
circleInOut: function(t, c, b) {
t *= 2;
if (t < 1) {
return 0.5 * -b * (Math.sqrt(1 - t * t) - 1) + c;
} else {
t -= 2;
return 0.5 * b * (Math.sqrt(1 - t * t) + 1) + c;
}
},
quadraticIn: function(t, c, b) {
return b * t * t + c;
},
quadraticOut: function(t, c, b) {
return -b * t * (t - 2) + c;
}
};
})();