动画库tween.js

var Tween = {

Linear:function (start,alter,curTime,dur) {return start+curTime/dur*alter;},//最简单的线性变化,即匀速运动

Quad:{//二次方缓动

easeIn:function (start,alter,curTime,dur) {

return start+Math.pow(curTime/dur,2)*alter;

},

easeOut:function (start,alter,curTime,dur) {

var progress =curTime/dur;

return start-(Math.pow(progress,2)-2*progress)*alter;

},

easeInOut:function (start,alter,curTime,dur) {

var progress =curTime/dur*2;

return (progress<1?Math.pow(progress,2):-((--progress)*(progress-2) - 1))*alter/2+start;

}

},

Cubic:{//三次方缓动

easeIn:function (start,alter,curTime,dur) {

return start+Math.pow(curTime/dur,3)*alter;

},

easeOut:function (start,alter,curTime,dur) {

var progress =curTime/dur;

return start-(Math.pow(progress,3)-Math.pow(progress,2)+1)*alter;

},

easeInOut:function (start,alter,curTime,dur) {

var progress =curTime/dur*2;

return (progress<1?Math.pow(progress,3):((progress-=2)*Math.pow(progress,2) + 2))*alter/2+start;

}

},

Quart:{//四次方缓动

easeIn:function (start,alter,curTime,dur) {

return start+Math.pow(curTime/dur,4)*alter;

},

easeOut:function (start,alter,curTime,dur) {

var progress =curTime/dur;

return start-(Math.pow(progress,4)-Math.pow(progress,3)-1)*alter;

},

easeInOut:function (start,alter,curTime,dur) {

var progress =curTime/dur*2;

return (progress<1?Math.pow(progress,4):-((progress-=2)*Math.pow(progress,3) - 2))*alter/2+start;

}

},

Quint:{//五次方缓动

easeIn:function (start,alter,curTime,dur) {

return start+Math.pow(curTime/dur,5)*alter;

},

easeOut:function (start,alter,curTime,dur) {

var progress =curTime/dur;

return start-(Math.pow(progress,5)-Math.pow(progress,4)+1)*alter;

},

easeInOut:function (start,alter,curTime,dur) {

var progress =curTime/dur*2;

return (progress<1?Math.pow(progress,5):((progress-=2)*Math.pow(progress,4) +2))*alter/2+start;

}

},

Sine :{//正弦曲线缓动

easeIn:function (start,alter,curTime,dur) {

return start-(Math.cos(curTime/dur*Math.PI/2)-1)*alter;

},

easeOut:function (start,alter,curTime,dur) {

return start+Math.sin(curTime/dur*Math.PI/2)*alter;

},

easeInOut:function (start,alter,curTime,dur) {

return start-(Math.cos(curTime/dur*Math.PI/2)-1)*alter/2;

}

},

Expo: {//指数曲线缓动

easeIn:function (start,alter,curTime,dur) {

return curTime?(start+alter*Math.pow(2,10*(curTime/dur-1))):start;

},

easeOut:function (start,alter,curTime,dur) {

return (curTime==dur)?(start+alter):(start-(Math.pow(2,-10*curTime/dur)+1)*alter);

},

easeInOut:function (start,alter,curTime,dur) {

if (!curTime) {return start;}

if (curTime==dur) {return start+alter;}

var progress =curTime/dur*2;

if (progress < 1) {

return alter/2*Math.pow(2,10* (progress-1))+start;

} else {

return alter/2* (-Math.pow(2, -10*--progress) + 2) +start;

}

}

},

Circ :{//圆形曲线缓动

easeIn:function (start,alter,curTime,dur) {

return start-alter*Math.sqrt(-Math.pow(curTime/dur,2));

},

easeOut:function (start,alter,curTime,dur) {

return start+alter*Math.sqrt(1-Math.pow(curTime/dur-1));

},

easeInOut:function (start,alter,curTime,dur) {

var progress =curTime/dur*2;

return (progress<1?1-Math.sqrt(1-Math.pow(progress,2)):(Math.sqrt(1 - Math.pow(progress-2,2)) + 1))*alter/2+start;

}

},

Elastic: {//指数衰减的正弦曲线缓动

easeIn:function (start,alter,curTime,dur,extent,cycle) {

if (!curTime) {return start;}

if ((curTime==dur)==1) {return start+alter;}

if (!cycle) {cycle=dur*0.3;}

var s;

if (!extent || extent< Math.abs(alter)) {

extent=alter;

s = cycle/4;

} else {s=cycle/(Math.PI*2)*Math.asin(alter/extent);}

return start-extent*Math.pow(2,10*(curTime/dur-1)) * Math.sin((curTime-dur-s)*(2*Math.PI)/cycle);

},

easeOut:function (start,alter,curTime,dur,extent,cycle) {

if (!curTime) {return start;}

if (curTime==dur) {return start+alter;}

if (!cycle) {cycle=dur*0.3;}

var s;

if (!extent || extent< Math.abs(alter)) {

extent=alter;

s =cycle/4;

} else {s=cycle/(Math.PI*2)*Math.asin(alter/extent);}

return start+alter+extent*Math.pow(2,-curTime/dur*10)*Math.sin((curTime-s)*(2*Math.PI)/cycle);

},

easeInOut:function (start,alter,curTime,dur,extent,cycle) {

if (!curTime) {return start;}

if (curTime==dur) {return start+alter;}

if (!cycle) {cycle=dur*0.45;}

var s;

if (!extent || extent< Math.abs(alter)) {

extent=alter;

s =cycle/4;

} else {s=cycle/(Math.PI*2)*Math.asin(alter/extent);}

var progress = curTime/dur*2;

if (progress<1) {

return start-0.5*extent*Math.pow(2,10*(progress-=1))*Math.sin( (progress*dur-s)*(2*Math.PI)/cycle);

} else {

return start+alter+0.5*extent*Math.pow(2,-10*(progress-=1)) * Math.sin( (progress*dur-s)*(2*Math.PI)/cycle);

}

}

},

Back:{

easeIn: function (start,alter,curTime,dur,s){

if (typeof s == "undefined") {s = 1.70158;}

return start+alter*(curTime/=dur)*curTime*((s+1)*curTime - s);

},

easeOut: function (start,alter,curTime,dur,s) {

if (typeof s == "undefined") {s = 1.70158;}

return start+alter*((curTime=curTime/dur-1)*curTime*((s+1)*curTime + s) + 1);

},

easeInOut: function (start,alter,curTime,dur,s){

if (typeof s == "undefined") {s = 1.70158;}

if ((curTime/=dur/2) < 1) {

return start+alter/2*(Math.pow(curTime,2)*(((s*=(1.525))+1)*curTime- s));

}

return start+alter/2*((curTime-=2)*curTime*(((s*=(1.525))+1)*curTime+ s)+2);

}

},

Bounce:{

easeIn: function(start,alter,curTime,dur){

return start+alter-Tween.Bounce.easeOut(0,alter,dur-curTime,dur);

},

easeOut: function(start,alter,curTime,dur){

if ((curTime/=dur) < (1/2.75)) {

return alter*(7.5625*Math.pow(curTime,2))+start;

} else if (curTime < (2/2.75)) {

return alter*(7.5625*(curTime-=(1.5/2.75))*curTime + .75)+start;

} else if (curTime< (2.5/2.75)) {

return alter*(7.5625*(curTime-=(2.25/2.75))*curTime + .9375)+start;

} else {

return alter*(7.5625*(curTime-=(2.625/2.75))*curTime + .984375)+start;

}

},

easeInOut: function (start,alter,curTime,dur){

if (curTime< dur/2) {

return Tween.Bounce.easeIn(0,alter,curTime*2,dur) *0.5+start;

} else {

return Tween.Bounce.easeOut(0,alter,curTime*2-dur,dur) *0.5 + alter*0.5 +start;

}

}

}

};

动画库tween.js的更多相关文章

  1. 聊聊JS动画库:Velocity.js

    前言 又到了炎热的7月,很久没有更新技术文章了,原因是上月月底实习结束,从公司离职.然后最近在弄自己的项目和考驾照,为了下次公司的应聘做准备,送别了女朋友到外地,哩哩啦啦半个月把一切事情都办妥后,还是 ...

  2. 详解tween.js 中文使用指南

    补间(动画)是一个概念,允许你以平滑的方式更改对象的属性.你只需告诉它哪些属性要更改,当补间结束运行时它们应该具有哪些最终值,以及这需要多长时间,补间引擎将负责计算从起始点到结束点的值. 例如,pos ...

  3. tween.js 中文使用指南

    tween.js 英文使用指南 首先来看个例子: hello,tween.js 补间(动画)(来自 in-between)是一个概念,允许你以平滑的方式更改对象的属性.你只需告诉它哪些属性要更改,当补 ...

  4. tween.js是一款可生成平滑动画效果的js动画库。tween.js允许你以平滑的方式修改元素的属性值。它可以通过设置生成各种类似CSS3的动画效果。

    简要教程 tween.js是一款可生成平滑动画效果的js动画库.相关的动画库插件还有:snabbt.js 强大的jQuery动画库插件和Tweene-超级强大的jQuery动画代理插件. tween. ...

  5. Jwalk发布——一个比较小的Js动画库

    断断续续折腾了几个晚上终于于周日把Jwalk发布了,顺便用了下yahoo的前端框架-pure css ,很简洁,非常帅.推荐使用以下. 下面说下Jwalk是做什么的: 前端开发过程中经常会用到一些动画 ...

  6. JS动画之缓动函数分析及动画库

    上一篇讲了JS动画定时器相关知识,这一篇介绍下缓动函数及流行的动画库. 熟悉的图 实际使用 jquery animate()+jquery.easing插件的使用: $(selector).anima ...

  7. 利用tween.js算法生成缓动效果

    在讲tween类之前,不得不提的是贝塞尔曲线了.首先,贝塞尔曲线是指依据四个位置任意的点坐标绘制出的一条光滑曲线.它在作图工具或动画中中运用得比较多,例如PS中的钢笔工具,firework中的画笔等等 ...

  8. Snabbt.js – 极简的 JavaScript 动画库

    Snabbt.js 是一个简约的 JavaScript 动画库.它会平移,旋转,缩放,倾斜和调整你的元素.通过矩阵乘法运算,变换等可以任何你想要的方式进行组合.最终的结果通过 CSS3 变换矩阵设置. ...

  9. aos.js超赞页面滚动元素动画jQuery动画库

    插件描述:aos.js 是一款效果超赞的页面滚动元素动画jQuery动画库插件.该动画库可以在页面滚动时提供28种不同的元素动画效果,以及多种easing效果.在页面往回滚动时,元素会恢复到原来的状态 ...

随机推荐

  1. 使用windows操作EXCEL如何关闭EXCEL进程

    经常项目上有导入excel的需求,其实导入一个固定格式的excel数据非常容易,但是,发现一个问题就是,导入excel后,用户在打开excel时,必须要打开2次才能打开excel,这让人很不爽:开始查 ...

  2. jQuery根据属性模糊匹配元素

    1.查看带有指定属性的元素: [attribute] 例如: $("div[id]") 2.查看属性值是某个特定值的元素: [attribute=value] 例如: $(&quo ...

  3. 显示倒计时的Button按钮

    package com.pingyijinren.helloworld.activity; import android.os.CountDownTimer; import android.suppo ...

  4. DatePickerDialog

    package com.pingyijinren.helloworld.activity; import android.app.DatePickerDialog; import android.su ...

  5. Spring MVC表单实例

    以下内容引用自http://wiki.jikexueyuan.com/project/spring/mvc-framework/spring-mvc-form-handling-example.htm ...

  6. android手机rootROM下载地址

    https://download.mokeedev.com/ https://download.lineageos.org/

  7. java.util.MissingResourceException: Can't find resource for bundle oracle.sysman.db.rsc.LoginResourc

    http://blog.itpub.net/197458/viewspace-1055358/   oracle 10.2.0.4 windows 2003 X64 平台 系统安装EMCA正常.第一次 ...

  8. 【转】AOP

    原文:http://blog.csdn.net/zhoudaxia/article/details/38502347 .---------------------------------------- ...

  9. [转]用AOP改善javascript代码

    有时候,不光要低头写代码,也要学着站在更高的角度,来思考代码怎么写,下面这篇文章,讲的关于代码设计的问题,脑洞大开. 原文: http://www.alloyteam.com/2013/08/yong ...

  10. javascript 自定义错误处理

    php 中是可以自定义程序的错误和异常处理函数的(handler).于是,我在想,javascript 中是否也存在和PHP中一样的异常和错误处理函数呢? try{}catch(){} 这种捕捉异常和 ...