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

首頁 > 語言 > JavaScript > 正文

javascript動畫算法實例分析

2024-05-06 16:24:11
字體:
來源:轉載
供稿:網友

這篇文章主要介紹了javascript動畫算法,實例分析了javascript實現動畫效果的實現及使用技巧,需要的朋友可以參考下

本文實例講述了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如下:

 

 
  1. Tween = {  
  2. Linear: function(t,b,c,d){ return c*t/d + b; }, 
  3. Quad: { 
  4. easeIn: function(t,b,c,d){ 
  5. return c*(t/=d)*t + b; 
  6. }, 
  7. easeOut: function(t,b,c,d){ 
  8. return -c *(t/=d)*(t-2) + b; 
  9. }, 
  10. easeInOut: function(t,b,c,d){ 
  11. if ((t/=d/2) < 1) return c/2*t*t + b; 
  12. return -c/2 * ((--t)*(t-2) - 1) + b; 
  13. }, 
  14. Cubic: { 
  15. easeIn: function(t,b,c,d){ 
  16. return c*(t/=d)*t*t + b; 
  17. }, 
  18. easeOut: function(t,b,c,d){ 
  19. return c*((t=t/d-1)*t*t + 1) + b; 
  20. }, 
  21. easeInOut: function(t,b,c,d){ 
  22. if ((t/=d/2) < 1) return c/2*t*t*t + b; 
  23. return c/2*((t-=2)*t*t + 2) + b; 
  24. }, 
  25. Quart: { 
  26. easeIn: function(t,b,c,d){ 
  27. return c*(t/=d)*t*t*t + b; 
  28. }, 
  29. easeOut: function(t,b,c,d){ 
  30. return -c * ((t=t/d-1)*t*t*t - 1) + b; 
  31. }, 
  32. easeInOut: function(t,b,c,d){ 
  33. if ((t/=d/2) < 1) return c/2*t*t*t*t + b; 
  34. return -c/2 * ((t-=2)*t*t*t - 2) + b; 
  35. }, 
  36. Quint: { 
  37. easeIn: function(t,b,c,d){ 
  38. return c*(t/=d)*t*t*t*t + b; 
  39. }, 
  40. easeOut: function(t,b,c,d){ 
  41. return c*((t=t/d-1)*t*t*t*t + 1) + b; 
  42. }, 
  43. easeInOut: function(t,b,c,d){ 
  44. if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b; 
  45. return c/2*((t-=2)*t*t*t*t + 2) + b; 
  46. }, 
  47. Sine: { 
  48. easeIn: function(t,b,c,d){ 
  49. return -c * Math.cos(t/d * (Math.PI/2)) + c + b; 
  50. }, 
  51. easeOut: function(t,b,c,d){ 
  52. return c * Math.sin(t/d * (Math.PI/2)) + b; 
  53. }, 
  54. easeInOut: function(t,b,c,d){ 
  55. return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b; 
  56. }, 
  57. Expo: { 
  58. easeIn: function(t,b,c,d){ 
  59. return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b; 
  60. }, 
  61. easeOut: function(t,b,c,d){ 
  62. return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b; 
  63. }, 
  64. easeInOut: function(t,b,c,d){ 
  65. if (t==0) return b; 
  66. if (t==d) return b+c; 
  67. if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b; 
  68. return c/2 * (-Math.pow(2, -10 * --t) + 2) + b; 
  69. }, 
  70. Circ: { 
  71. easeIn: function(t,b,c,d){ 
  72. return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b; 
  73. }, 
  74. easeOut: function(t,b,c,d){ 
  75. return c * Math.sqrt(1 - (t=t/d-1)*t) + b; 
  76. }, 
  77. easeInOut: function(t,b,c,d){ 
  78. if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b; 
  79. return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b; 
  80. }, 
  81. Elastic: { 
  82. easeIn: function(t,b,c,d,a,p){ 
  83. if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3; 
  84. if (!a || a < Math.abs(c)) { a=c; var s=p/4; } 
  85. else var s = p/(2*Math.PI) * Math.asin (c/a); 
  86. return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; 
  87. }, 
  88. easeOut: function(t,b,c,d,a,p){ 
  89. if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3; 
  90. if (!a || a < Math.abs(c)) { a=c; var s=p/4; } 
  91. else var s = p/(2*Math.PI) * Math.asin (c/a); 
  92. return (a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b); 
  93. }, 
  94. easeInOut: function(t,b,c,d,a,p){ 
  95. if (t==0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(.3*1.5); 
  96. if (!a || a < Math.abs(c)) { a=c; var s=p/4; } 
  97. else var s = p/(2*Math.PI) * Math.asin (c/a); 
  98. if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; 
  99. return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b; 
  100. }, 
  101. Back: { 
  102. easeIn: function(t,b,c,d,s){ 
  103. if (s == undefined) s = 1.70158; 
  104. return c*(t/=d)*t*((s+1)*t - s) + b; 
  105. }, 
  106. easeOut: function(t,b,c,d,s){ 
  107. if (s == undefined) s = 1.70158; 
  108. return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b; 
  109. }, 
  110. easeInOut: function(t,b,c,d,s){ 
  111. if (s == undefined) s = 1.70158;  
  112. if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; 
  113. return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; 
  114. }, 
  115. Bounce: { 
  116. easeIn: function(t,b,c,d){ 
  117. return c - Tween.Bounce.easeOut(d-t, 0, c, d) + b; 
  118. }, 
  119. easeOut: function(t,b,c,d){ 
  120. if ((t/=d) < (1/2.75)) { 
  121. return c*(7.5625*t*t) + b; 
  122. else if (t < (2/2.75)) { 
  123. return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b; 
  124. else if (t < (2.5/2.75)) { 
  125. return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b; 
  126. else { 
  127. return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b; 
  128. }, 
  129. easeInOut: function(t,b,c,d){ 
  130. if (t < d/2) return Tween.Bounce.easeIn(t*2, 0, c, d) * .5 + b; 
  131. else return Tween.Bounce.easeOut(t*2-d, 0, c, d) * .5 + c*.5 + b; 

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表

圖片精選

主站蜘蛛池模板: 黔西县| 巴东县| 敦化市| 淳安县| 孟州市| 二手房| 乡城县| 石屏县| 阆中市| 城口县| 澄迈县| 远安县| 靖西县| 西畴县| 社旗县| 东光县| 日土县| 县级市| 宁津县| 全州县| 长兴县| 隆德县| 雅安市| 遵义市| 门头沟区| 祁东县| 马龙县| 鸡泽县| 井陉县| 绍兴县| 陵水| 屏东县| 高邑县| 江都市| 康马县| 平湖市| 茂名市| 利辛县| 子洲县| 天峻县| 葵青区|