动画库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. hdu 2181暴搜

    #include<stdio.h> #include<string.h> #define N 30 int map[N][4],total; void dfs(int n,in ...

  2. poj2186 求有向图G中所有点都能到达的点的数量

    /*题意:有向图,求这样的点的数量:所有点都能到达它.缩点成有向无环图,思:如果该强连通有出度,那么 从该出度出去的边必然回不来(已经缩点了),所以有出度的强连通必然不是.那么是不是所有出度为0的强连 ...

  3. noip 2015 day1

    T1 神奇的幻方 题目描述 幻方是一种很神奇的N*N矩阵:它由数字1,2,3,……,N*N构成,且每行.每列及两条对角线上的数字之和都相同. 当N为奇数时,我们可以通过以下方法构建一个幻方: 首先将1 ...

  4. java基础编程题

    1. 某公司每月标准上班时间是160小时,每小时工资是30元. 如果上班时间超出了160小时,超出部分每小时按1.5倍工资发放.请编写程序计算员工月工资. package com.num2.lianx ...

  5. 转:浅谈Linux的内存管理机制

    一 物理内存和虚拟内存          我们知道,直接从物理内存读写数据要比从硬盘读写数据要快的多,因此,我们希望所有数据的读取和写入都在内存完成,而内存是有限的,这样就引出了物理内存与虚拟内存的概 ...

  6. 【神乎其神】这些EXCEL技巧,太神奇了,赶紧收藏!

    转:http://learning.sohu.com/20160215/n437421658.shtml

  7. java比较两个日期大小

    方法一 /** * 比较两个日期之间的大小 * * @param d1 * @param d2 * @return 前者大于后者返回true 反之false */ public boolean com ...

  8. DELPHI跨平台的临界替代者

    在WINDOWS里面使用临界来保护多线程需要访问的共享对象,现在,DELPHI有了新的跨平台临界保护者--System.TMonitor 代码演示如下: FConnections := TObject ...

  9. [PythonCode]扫描局域网的alive ip地址

    内网的主机都是自己主动分配ip地址,有时候须要查看下有那些ip在使用,就写了个简单的脚本. linux和windows下都能够用,用多线程来ping1-255全部的地址,效率不高.2分钟左右. 先凑合 ...

  10. CSS浮动通俗讲解

    首先要知道,div是块级元素,在页面中独占一行,自上而下排列,也就是传说中的流.如下图: 可以看出,即使div1的宽度很小,页面中一行可以容下div1和div2,div2也不会排在div1后边,因为d ...