缓动函数 Easing Functions |
您所在的位置:网站首页 › 德阳高档楼盘 › 缓动函数 Easing Functions |
缓动函数 Easing Functions
缓动函数 自定义参数随时间变化的速率。 常见效果Linear:无缓动效果; Quadratic:二次方的缓动(t^2); Sinusoidal:正弦曲线的缓动(sin(t)); Exponential:指数曲线的缓动(2^t); Circular:圆形曲线的缓动(sqrt(1-t^2)); Cubic:三次方的缓动(t^3); Quartic:四次方的缓动(t^4); Quintic:五次方的缓动(t^5); Elastic:指数衰减的正弦曲线缓动; Back:超过范围的三次方缓动((s+1)t^3 - st^2); Bounce:指数衰减的反弹缓动。 缓动方式每个效果都分三个缓动方式(方法),分别是: easeIn:从0开始加速的缓动; easeOut:减速到0的缓动; easeInOut:前半段从0开始加速,后半段减速到0的缓动。 具体如图所示: 每个函数包含 t、b、c 和 d 四个参数 t = Time - 表示动画开始以来经过的时间。通常从0开始,通过游戏循环或update函数来缓慢增加。b = Beginning value - 动画的起点,默认从0开始。c = Change in value - 从起点到终点的差值。d = Duration - 完成动画所需的时间。使用示例 t = 0 - 动画从0s开始 b = 200 - 对象 x 坐标的起始位置为200 c = 300 - 对象必须向右移动 300,到500 结束 d = 1 - 对象用 1 秒时间来完成从 200 到 500 的移动 Linear 线性 function easeLinear (t, b, c, d) { return c * t / d + b; } Quadratic 二次渐变Quadratic easing in function easeInQuad (t, b, c, d) { return c * (t /= d) * t + b; }Quadratic easing out function easeOutQuad (t, b, c, d) { return -c * (t /= d) * (t - 2) + b; }Quadratic easing in and out function easeInOutQuad (t, b, c, d) { if ((t /= d / 2) return c * Math.sin(t / d * (Math.PI / 2)) + b; }Sinusoidal easing in and out function easeInOutSine (t, b, c, d) { return -c / 2 * (Math.cos(Math.PI * t / d) - 1) + b; } Exponential 指数渐变Exponential easing in function easeInExpo (t, b, c, d) { return (t == 0) ? b : c * Math.pow(2, 10 * (t / d - 1)) + b; }Exponential easing out function easeOutExpo (t, b, c, d) { return (t == d) ? b + c : c * (-Math.pow(2, -10 * t / d) + 1) + b; }Exponential easing in and out function easeInOutExpo (t, b, c, d) { if (t == 0) return b; if (t == d) return b + c; if ((t /= d / 2) return c * Math.sqrt(1 - (t = t / d - 1) * t) + b; }Circular easing in and out function easeInOutCirc (t, b, c, d) { if ((t /= d / 2) return c * ((t = t / d - 1) * t * t + 1) + b; }Cubic easing in and out function easeInOutCubic (t, b, c, d) { if ((t /= d / 2) return -c * ((t = t / d - 1) * t * t * t - 1) + b; }Quartic easing in and out function easeInOutQuart (t, b, c, d) { if ((t /= d / 2) return c * ((t = t / d - 1) * t * t * t * t + 1) + b; }Quintic easing in and out function easeInOutQuint (t, b, c, d) { if ((t /= d / 2) a = c; var s = p / 4; } else var s = p / (2 * Math.PI) * Math.asin(c / a); return -(a * Math.pow(2, 10 * (t -= 1)) * Math.sin((t * d - s) * (2 * Math.PI) / p)) + b; }Elastic easing out function easeOutElastic (t, b, c, d) { var s = 1.70158; var p = 0; var a = c; if (t == 0) return b; if ((t /= d) == 1) return b + c; if (!p) p = d * .3; if (a var s = 1.70158; var p = 0; var a = c; if (t == 0) return b; if ((t /= d / 2) == 2) return b + c; if (!p) p = d * (.3 * 1.5); if (a if (s == undefined) s = 1.70158; return c * (t /= d) * t * ((s + 1) * t - s) + b; }Back easing out function easeOutBack (t, b, c, d) { if (s == undefined) s = 1.70158; return c * ((t = t / d - 1) * t * ((s + 1) * t + s) + 1) + b; }Back easing in and out function easeInOutBack (t, b, c, d) { if (s == undefined) s = 1.70158; if ((t /= d / 2) if ((t/=d) return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b; } else if (t return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b; } }Bounce easing in and out function easeInOutBounce(t, b, c, d) { if (t |
今日新闻 |
点击排行 |
|
推荐新闻 |
图片新闻 |
|
专题文章 |
CopyRight 2018-2019 实验室设备网 版权所有 win10的实时保护怎么永久关闭 |