Created
November 11, 2014 02:23
-
-
Save JoeKeikun/d0f23257bd415d1a6926 to your computer and use it in GitHub Desktop.
jquery ui提取出来的时间处理函数
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var timingfunction = {}; | |
/** | |
* linear 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.linear = function(p) { | |
return p; | |
}; | |
/** | |
* swing 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.swing = function(p) { | |
return .5 - Math.cos(p * Math.PI) / 2; | |
}; | |
/** | |
* easeInQuad 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeInQuad = function(p) { | |
return Math.pow(p, 2); | |
}; | |
/** | |
* easeOutQuad 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeOutQuad = function(p) { | |
return 1 - timingfunction.easeInQuad(1 - p); | |
}; | |
/** | |
* easeInOutQuad 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeInOutQuad = function(p) { | |
return p < 0.5 ? | |
timingfunction.easeInQuad(p * 2) / 2 : | |
1 - timingfunction.easeInQuad(p * -2 + 2) / 2; | |
}; | |
/** | |
* easeInCubic 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeInCubic = function(p) { | |
return Math.pow(p, 3); | |
}; | |
/** | |
* easeOutCubic 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeOutCubic = function(p) { | |
return 1 - timingfunction.easeInCubic(1 - p); | |
}; | |
/** | |
* easeInOutCubic 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeInOutCubic = function(p) { | |
return p < 0.5 ? | |
timingfunction.easeInCubic(p * 2) / 2 : | |
1 - timingfunction.easeInCubic(p * -2 + 2) / 2; | |
}; | |
/** | |
* easeInQuart 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeInQuart = function(p) { | |
return Math.pow(p, 4); | |
}; | |
/** | |
* easeOutQuart 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeOutQuart = function(p) { | |
return 1 - timingfunction.easeInQuart(1 - p); | |
}; | |
/** | |
* easeInOutQuart 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeInOutQuart = function(p) { | |
return p < 0.5 ? | |
timingfunction.easeInQuart(p * 2) / 2 : | |
1 - timingfunction.easeInQuart(p * -2 + 2) / 2; | |
}; | |
/** | |
* easeInQuint 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeInQuint = function(p) { | |
return Math.pow(p, 5); | |
}; | |
/** | |
* easeOutQuint 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeOutQuint = function(p) { | |
return 1 - timingfunction.easeInQuint(1 - p); | |
}; | |
/** | |
* easeInOutQuint 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeInOutQuint = function(p) { | |
return p < 0.5 ? | |
timingfunction.easeInQuint(p * 2) / 2 : | |
1 - timingfunction.easeInQuint(p * -2 + 2) / 2; | |
}; | |
/** | |
* easeInExpo 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeInExpo = function(p) { | |
return Math.pow(p, 6); | |
}; | |
/** | |
* easeOutExpo 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeOutExpo = function(p) { | |
return 1 - timingfunction.easeInExpo(1 - p); | |
}; | |
/** | |
* easeInOutExpo 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeInOutExpo = function(p) { | |
return p < 0.5 ? | |
timingfunction.easeInExpo(p * 2) / 2 : | |
1 - timingfunction.easeInExpo(p * -2 + 2) / 2; | |
}; | |
/** | |
* easeInSine 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeInSine = function(p) { | |
return 1 - Math.cos(p * Math.PI / 2); | |
}; | |
/** | |
* easeOutSine 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeOutSine = function(p) { | |
return 1 - timingfunction.easeInSine(1 - p); | |
}; | |
/** | |
* easeInOutSine 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeInOutSine = function(p) { | |
return p < 0.5 ? | |
timingfunction.easeInSine(p * 2) / 2 : | |
1 - timingfunction.easeInSine(p * -2 + 2) / 2; | |
}; | |
/** | |
* easeInCirc 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeInCirc = function(p) { | |
return 1 - Math.sqrt(1 - p * p); | |
}; | |
/** | |
* easeOutCirc 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeOutCirc = function(p) { | |
return 1 - timingfunction.easeInCirc(1 - p); | |
}; | |
/** | |
* easeInOutCirc 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeInOutCirc = function(p) { | |
return p < 0.5 ? | |
timingfunction.easeInCirc(p * 2) / 2 : | |
1 - timingfunction.easeInCirc(p * -2 + 2) / 2; | |
}; | |
/** | |
* easeInElastic 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeInElastic = function(p) { | |
return p === 0 || p === 1 ? p : | |
-Math.pow(2, 8 * (p - 1)) * Math.sin(((p - 1) * 80 - 7.5) * Math.PI / 15); | |
}; | |
/** | |
* easeOutElastic 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeOutElastic = function(p) { | |
return 1 - timingfunction.easeInElastic(1 - p); | |
}; | |
/** | |
* easeInOutElastic 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeInOutElastic = function(p) { | |
return p < 0.5 ? | |
timingfunction.easeInElastic(p * 2) / 2 : | |
1 - timingfunction.easeInElastic(p * -2 + 2) / 2; | |
}; | |
/** | |
* easeInBack 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeInBack = function(p) { | |
return p * p * (3 * p - 2); | |
}; | |
/** | |
* easeOutBack 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeOutBack = function(p) { | |
return 1 - timingfunction.easeInBack(1 - p); | |
}; | |
/** | |
* easeInOutBack 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeInOutBack = function(p) { | |
return p < 0.5 ? | |
timingfunction.easeInBack(p * 2) / 2 : | |
1 - timingfunction.easeInBack(p * -2 + 2) / 2; | |
}; | |
/** | |
* easeInBounce 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeInBounce = function(p) { | |
var pow2, | |
bounce = 4; | |
while (p < ((pow2 = Math.pow(2, --bounce)) - 1) / 11) {}; | |
return 1 / Math.pow(4, 3 - bounce) - 7.5625 * Math.pow((pow2 * 3 - 2) / 22 - p, 2); | |
}; | |
/** | |
* easeOutBounce 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeOutBounce = function(p) { | |
return 1 - timingfunction.easeInBounce(1 - p); | |
}; | |
/** | |
* easeInOutBounce 函数 | |
* | |
* @param {Number} p 正常百分比值 | |
* @return {Number} 换算后的结果 | |
*/ | |
timingfunction.easeInOutBounce = function(p) { | |
return p < 0.5 ? | |
timingfunction.easeInBounce(p * 2) / 2 : | |
1 - timingfunction.easeInBounce(p * -2 + 2) / 2; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment