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

首頁 > 語言 > JavaScript > 正文

tween.js緩動補(bǔ)間動畫算法示例

2024-05-06 15:21:47
字體:
供稿:網(wǎng)友

一、理解tween.js

如果看到上面的已經(jīng)理解了,可以跳過下面的部分.下面為對Tween.js的解釋 下面就介紹如何使用這個Tween了,首先b、c、d三個參數(shù)(即初始值,變化量,持續(xù)時間)在緩動開始前,是需要先確定好的。 首先引入一個概念就補(bǔ)間動畫 Flash做動畫時會用到Tween類,利用它可以做很多動畫效果,例如緩動、彈簧等等。 tween.js在Flash中可以解釋為補(bǔ)間動畫. 那么問題來了,什么是補(bǔ)間動畫呢?

相信學(xué)過Flash的都知道補(bǔ)間動畫是flash主要的非常重要的表現(xiàn)手段之一.補(bǔ)間動畫有動作補(bǔ)間動畫與形狀補(bǔ)間動畫兩種,但是在js中卻不需要了解這么多. 好了,廢話不多說,先看看百度百科關(guān)于補(bǔ)間動畫給出的定義: 補(bǔ)間動畫:做flash動畫時,在兩個關(guān)鍵幀中間需要做“補(bǔ)間動畫”,才能實(shí)現(xiàn)圖畫的運(yùn)動; 插入補(bǔ)間動畫后兩個關(guān)鍵幀之間的插補(bǔ)幀是由計算機(jī)自動運(yùn)算而得到的

那么什么是關(guān)鍵幀呢? 舉個栗子: 先科普一下,平常所看的電影,動畫都是24幀的,24幀為一秒.在人眼可以捕捉的范圍內(nèi).可以想象兩個點(diǎn)之間有有22個點(diǎn),形成一條直線或者曲線.而每一個點(diǎn)就代表一幀,幀——就是動畫中最小單位的單幅影像畫面,而單幅影像畫面就可以看做是一個對象(一切皆對象,除去值類型)了.而這條線就代表對象的運(yùn)動軌跡.

二、四個參數(shù)

    t: current time-->代表第一個點(diǎn),也就是第一幀,也就是一個動畫開始的地方。 b: beginning value-->代表初始值,也就是開始量,我們看電影或者動畫一般都不會看序幕把,那么跳過開頭部分,選擇第一幀和最后一幀之間你要開始看位置,而此位置就是初始值。 c: change in value-->代表的就是最后一幀減去初始值就是變化量, d: duration-->代表最后一幀,1s的結(jié)束,也是動畫的結(jié)束。

tween.js的使用 1.下載 2.引入 3.使用tween.js語法

Tween.緩動函數(shù)名.緩動效果名(t,b,c,d);

注意:當(dāng)開始步數(shù)增加到與結(jié)束步數(shù)相等時,整個運(yùn)動結(jié)束. 注注意:只有當(dāng)t增加到與d相等時才會結(jié)束運(yùn)動;如果不等,運(yùn)動不會停止.

三、tween文件代碼

/* * Tween.js * t: current time(當(dāng)前時間); * b: beginning value(初始值); * c: change in value(變化量); * d: duration(持續(xù)時間)。*/var 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: { //指數(shù)緩動效果    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: { //圓形緩動函數(shù)    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: { //指數(shù)衰減正弦曲線緩動函數(shù)    easeIn: function(t, b, c, d, a, p) { //加速      var s;      if (t==0) return b;      if ((t /= d) == 1) return b + c;      if (typeof p == "undefined") p = d * .3;      if (!a || a < Math.abs(c)) {        s = p / 4;        a = c;      } else {        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) { //減速      var s;      if (t==0) return b;      if ((t /= d) == 1) return b + c;      if (typeof p == "undefined") p = d * .3;      if (!a || a < Math.abs(c)) {        a = c;         s = p / 4;      } else {        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) { //先加速后減速      var s;      if (t==0) return b;      if ((t /= d / 2) == 2) return b+c;      if (typeof p == "undefined") p = d * (.3 * 1.5);      if (!a || a < Math.abs(c)) {        a = c;         s = p / 4;      } else {        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: { //超過范圍的三次方的緩動函數(shù)    easeIn: function(t, b, c, d, s) {      if (typeof s == "undefined") s = 1.70158;      return c * (t /= d) * t * ((s + 1) * t - s) + b;    },    easeOut: function(t, b, c, d, s) {      if (typeof 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 (typeof 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: { //指數(shù)衰減的反彈曲線緩動函數(shù)    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;      }    }  }}Math.tween = Tween;            
發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 吴江市| 南涧| 攀枝花市| 从化市| 萝北县| 弥勒县| 平安县| 卓资县| 任丘市| 新兴县| 辽宁省| 原阳县| 睢宁县| 沙湾县| 丰顺县| 平谷区| 广宁县| 汕尾市| 犍为县| 宜昌市| 天柱县| 天气| 尉犁县| 阿克| 临桂县| 壶关县| 延川县| 东兴市| 北辰区| 莱西市| 双城市| 定陶县| 崇礼县| 濮阳县| 自贡市| 积石山| 镇康县| 平山县| 南华县| 田东县| 梓潼县|