国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

javascript動畫算法實例分析

2019-11-20 11:57:01
字體:
來源:轉載
供稿:網友

本文實例講述了javascript動畫算法。分享給大家供大家參考。具體如下:

動畫算法

Linear:無緩動效果(勻速運動);
Quadratic:二次方的緩動;
Cubic:三次方的緩動
Quartic:四次方的緩動;
Quintic:五次方的緩動;
Sinusoidal:正弦曲線的緩動;
Exponential:指數曲線的緩動;
Circular:圓形曲線的緩動;
Elastic:指數衰減的正弦曲線緩動;
Back:超過范圍的三次方緩動);
Bounce:指數衰減的反彈緩動。

每個效果都分三個緩動方式(方法),分別是:

easeIn:從0開始加速的運動;
easeOut:減速到0的運動;
easeInOut:前半段從0開始加速,后半段減速到0的運動。

函數的四個參數分別代表:

t--- current time(當前時間);
b--- beginning value(初始值);
c--- change in value(變化量);
d---duration(持續時間)

運算的結果就是當前的運動路程。

Tween.js如下:

Tween = {  Linear: function(t,b,c,d){ return c*t/d + b; }, Quad: {  easeIn: function(t,b,c,d){   return c*(t/=d)*t + b;  },  easeOut: function(t,b,c,d){   return -c *(t/=d)*(t-2) + b;  },  easeInOut: function(t,b,c,d){   if ((t/=d/2) < 1) return c/2*t*t + b;   return -c/2 * ((--t)*(t-2) - 1) + b;  } }, Cubic: {  easeIn: function(t,b,c,d){   return c*(t/=d)*t*t + b;  },  easeOut: function(t,b,c,d){   return c*((t=t/d-1)*t*t + 1) + b;  },  easeInOut: function(t,b,c,d){   if ((t/=d/2) < 1) return c/2*t*t*t + b;   return c/2*((t-=2)*t*t + 2) + b;  } }, Quart: {  easeIn: function(t,b,c,d){   return c*(t/=d)*t*t*t + b;  },  easeOut: function(t,b,c,d){   return -c * ((t=t/d-1)*t*t*t - 1) + b;  },  easeInOut: function(t,b,c,d){   if ((t/=d/2) < 1) return c/2*t*t*t*t + b;   return -c/2 * ((t-=2)*t*t*t - 2) + b;  } }, Quint: {  easeIn: function(t,b,c,d){   return c*(t/=d)*t*t*t*t + b;  },  easeOut: function(t,b,c,d){   return c*((t=t/d-1)*t*t*t*t + 1) + b;  },  easeInOut: function(t,b,c,d){   if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b;   return c/2*((t-=2)*t*t*t*t + 2) + b;  } }, Sine: {  easeIn: function(t,b,c,d){   return -c * Math.cos(t/d * (Math.PI/2)) + c + b;  },  easeOut: function(t,b,c,d){   return c * Math.sin(t/d * (Math.PI/2)) + b;  },  easeInOut: function(t,b,c,d){   return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b;  } }, Expo: {  easeIn: function(t,b,c,d){   return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b;  },  easeOut: function(t,b,c,d){   return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b;  },  easeInOut: function(t,b,c,d){   if (t==0) return b;   if (t==d) return b+c;   if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b;   return c/2 * (-Math.pow(2, -10 * --t) + 2) + b;  } }, Circ: {  easeIn: function(t,b,c,d){   return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b;  },  easeOut: function(t,b,c,d){   return c * Math.sqrt(1 - (t=t/d-1)*t) + b;  },  easeInOut: function(t,b,c,d){   if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b;   return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b;  } }, Elastic: {  easeIn: function(t,b,c,d,a,p){   if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;   if (!a || a < Math.abs(c)) { 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;  },  easeOut: function(t,b,c,d,a,p){   if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3;   if (!a || a < Math.abs(c)) { a=c; var s=p/4; }   else var s = p/(2*Math.PI) * Math.asin (c/a);   return (a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b);  },  easeInOut: function(t,b,c,d,a,p){   if (t==0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(.3*1.5);   if (!a || a < Math.abs(c)) { a=c; var s=p/4; }   else var s = p/(2*Math.PI) * Math.asin (c/a);   if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b;   return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b;  } }, Back: {  easeIn: function(t,b,c,d,s){   if (s == undefined) s = 1.70158;   return c*(t/=d)*t*((s+1)*t - s) + b;  },  easeOut: function(t,b,c,d,s){   if (s == undefined) s = 1.70158;   return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;  },  easeInOut: function(t,b,c,d,s){   if (s == undefined) s = 1.70158;    if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b;   return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b;  } }, Bounce: {  easeIn: function(t,b,c,d){   return c - Tween.Bounce.easeOut(d-t, 0, c, d) + b;  },  easeOut: function(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;   }  },  easeInOut: function(t,b,c,d){   if (t < d/2) return Tween.Bounce.easeIn(t*2, 0, c, d) * .5 + b;   else return Tween.Bounce.easeOut(t*2-d, 0, c, d) * .5 + c*.5 + b;  } }}

希望本文所述對大家的javascript程序設計有所幫助。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 阜南县| 黄陵县| 张家界市| 枣强县| 宜宾县| 明水县| 彩票| 东至县| 耒阳市| 文昌市| 桓台县| 镇巴县| 通榆县| 阳信县| 雅江县| 孝感市| 南川市| 宁乡县| 武城县| 西丰县| 遂川县| 建瓯市| 宝鸡市| 漯河市| 沙田区| 调兵山市| 申扎县| 尼玛县| 广元市| 石林| 即墨市| 龙口市| 分宜县| 蕉岭县| 康马县| 田林县| 黄浦区| 额尔古纳市| 安远县| 郑州市| 郑州市|