<script>

function startMove(obj,json,fn){
clearInterval(obj.timer);
obj.timer = setInterval(function(){ var bBtn = true; for(var attr in json){ var iCur = 0;
if(attr == 'opacity'){
iCur = Math.round(getStyle(obj,attr)*100);
}
else{
iCur = parseInt(getStyle(obj,attr));
} var iSpeed = (json[attr] - iCur)/5;
iSpeed = iSpeed > 0 ? Math.ceil(iSpeed) : Math.floor(iSpeed); if(iCur != json[attr]){ bBtn = false;
} if(attr == 'opacity'){
obj.style.filter = 'alpha(opacity='+(iCur+iSpeed)+')';
obj.style.opacity = (iCur + iSpeed)/100;
}
else{
obj.style[attr] = iCur + iSpeed + 'px';
}
} if(bBtn){
clearInterval(obj.timer);
fn && fn.call(obj);
}
},30);
} function getStyle(obj,attr){
return obj.currentStyle?obj.currentStyle[attr]:getComputedStyle(obj,250)[attr];
} function startMove2(obj,json,times,fx,fn){ if( typeof times == 'undefined' ){
times = 400;
fx = 'linear';
} if( typeof times == 'string' ){
if(typeof fx == 'function'){
fn = fx;
}
fx = times;
times = 400;
}
else if(typeof times == 'function'){
fn = times;
times = 400;
fx = 'linear';
}
else if(typeof times == 'number'){
if(typeof fx == 'function'){
fn = fx;
fx = 'linear';
}
else if(typeof fx == 'undefined'){
fx = 'linear';
}
} var iCur = {}; for(var attr in json){
iCur[attr] = 0; if( attr == 'opacity' ){
if(Math.round(getStyle(obj,attr)*100) == 0){
iCur[attr] = 0;
}
else{
iCur[attr] = Math.round(getStyle(obj,attr)*100) || 100;
}
}
else{
iCur[attr] = parseInt(getStyle(obj,attr)) || 0;
} } var startTime = now(); clearInterval(obj.timer);
obj.timer = setInterval(function(){ var changeTime = now(); var scale = 1 - Math.max(0,startTime - changeTime + times)/times; for(var attr in json){ var value = Tween[fx](scale*times, iCur[attr] , json[attr] - iCur[attr] , times ); if(attr == 'opacity'){
obj.style.filter = 'alpha(opacity='+ value +')';
obj.style.opacity = value/100;
}
else{
obj.style[attr] = value + 'px';
} } if(scale == 1){
clearInterval(obj.timer);
if(fn){
fn.call(obj);
}
} },13); function now(){
return (new Date()).getTime();
} } var Tween = {
linear: function (t, b, c, d){ //鍖€閫�
return c*t/d + b;
},
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;
},
easeBoth: function(t, b, c, d){ //鍔犻€熷噺閫熸洸绾�
if ((t/=d/2) < 1) {
return c/2*t*t + b;
}
return -c/2 * ((--t)*(t-2) - 1) + b;
},
easeInStrong: function(t, b, c, d){ //鍔犲姞閫熸洸绾�
return c*(t/=d)*t*t*t + b;
},
easeOutStrong: function(t, b, c, d){ //鍑忓噺閫熸洸绾�
return -c * ((t=t/d-1)*t*t*t - 1) + b;
},
easeBothStrong: 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;
},
elasticIn: function(t, b, c, d, a, p){ //姝e鸡琛板噺鏇茬嚎锛堝脊鍔ㄦ笎鍏ワ級
if (t === 0) {
return b;
}
if ( (t /= d) == 1 ) {
return b+c;
}
if (!p) {
p=d*0.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;
},
elasticOut: function(t, b, c, d, a, p){ //姝e鸡澧炲己鏇茬嚎锛堝脊鍔ㄦ笎鍑猴級
if (t === 0) {
return b;
}
if ( (t /= d) == 1 ) {
return b+c;
}
if (!p) {
p=d*0.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;
},
elasticBoth: function(t, b, c, d, a, p){
if (t === 0) {
return b;
}
if ( (t /= d/2) == 2 ) {
return b+c;
}
if (!p) {
p = d*(0.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 - 0.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 )*0.5 + c + b;
},
backIn: function(t, b, c, d, s){ //鍥為€€鍔犻€燂紙鍥為€€娓愬叆锛�
if (typeof s == 'undefined') {
s = 1.70158;
}
return c*(t/=d)*t*((s+1)*t - s) + b;
},
backOut: function(t, b, c, d, s){
if (typeof s == 'undefined') {
s = 3.70158; //鍥炵缉鐨勮窛绂�
}
return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b;
},
backBoth: 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;
},
bounceIn: function(t, b, c, d){ //寮圭悆鍑忔尟锛堝脊鐞冩笎鍑猴級
return c - Tween['bounceOut'](d-t, 0, c, d) + b;
},
bounceOut: 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 + 0.75) + b;
} else if (t < (2.5/2.75)) {
return c*(7.5625*(t-=(2.25/2.75))*t + 0.9375) + b;
}
return c*(7.5625*(t-=(2.625/2.75))*t + 0.984375) + b;
},
bounceBoth: function(t, b, c, d){
if (t < d/2) {
return Tween['bounceIn'](t*2, 0, c, d) * 0.5 + b;
}
return Tween['bounceOut'](t*2-d, 0, c, d) * 0.5 + c*0.5 + b;
}
}
</script>

js 网上见到的动画函数 备份的更多相关文章

  1. js进阶 13 jquery动画函数有哪些

    js进阶 13 jquery动画函数有哪些 一.总结 一句话总结: 二.jquery动画函数有哪些 原生JavaScript编写动画效果代码比较复杂,而且还需要考虑兼容性.通过jQuery,我们使用简 ...

  2. js 封装一个均速动画函数

    //动画函数---任意一个元素移动到指定的目标位置 //element为元素 target为位置 function carToon(element, target) { //设置一个定时器让他循环去增 ...

  3. js进阶 13-6 jquery动画效果相关常用函数有哪些

    js进阶 13-6 jquery动画效果相关常用函数有哪些 一.总结 一句话总结:animate(),stop(),finish(),delat()四个. 1.stop()方法的基本用法是什么(sto ...

  4. js进阶 13-1 jquery动画中的显示隐藏函数有哪些

    js进阶 13-1 jquery动画中的显示隐藏函数有哪些 一.总结 一句话总结:show(),hide(),toggle(),这三个. 1.jquery动画中显示隐藏效果函数有哪些? show()h ...

  5. 原生JS实现动画函数的封装

    封装了一个JS方法,支持元素的基本动画:宽.高.透明度...等,也支持链式动画和同时运动. 获取元素的属性的函数并进行了兼容性处理: function getStyle(obj, attr) { if ...

  6. Js封装的动画函数实现轮播图

    ---恢复内容开始--- 效果图说明:当鼠标移到哪一个按钮上的时候会自动跳转到某一张图片上,并且按钮会以高亮显示 项目目录结构 用到的js封装的animate()动画         function ...

  7. js 变速动画函数

    //获取任意一个元素的任意一个属性的当前的值---当前属性的位置值 function getStyle(element, attr) { return window.getComputedStyle ...

  8. JS中的自执行函数

    本来规划的是2013年,狠狠的将JS学习下,谁知计划赶不上变化,计划泡汤了.13年的我对JS来说可以说是属于跟风,对它的理解和认识也仅仅是皮毛而已,也是因为要完成<ArcGIS API for ...

  9. 移动端 transition动画函数的封装(仿Zepto)以及 requestAnimationFrame动画函数封装(仿jQuery)

    移动端 css3 transition 动画 ,requestAnimationFrame 动画  对于性能的要求,h5优先考虑: 移动端 单页有时候 制作只用到简单的css3动画即可,我们封装一下, ...

随机推荐

  1. Android---53---多线程下载

    采用HttpURLConnection HttpURLConnection从继承URLConnection,它也可以被用来发送到指定的网站GET求 POST求. 办法: int getResponse ...

  2. 京东评论情感分类器(基于bag-of-words模型)

    京东评论情感分类器(基于bag-of-words模型) 近期在本来在研究paraVector模型,想拿bag-of-words来做对照. 数据集是京东的评论,经过人工挑选,选出一批正面和负面的评论. ...

  3. WebService(2)-XML系列之Java和Xml之间相互转换

    源代码下载:链接:http://pan.baidu.com/s/1ntL1a7R password: rwp1 本文主要讲述:使用jaxb完毕对象和xml之间的转换 TestJava2xml.java ...

  4. android学习一些帖子

    关于谷歌和苹果的帖子 http://news.eoe.cn/18576.html android无线调试的帖子: http://baoyz.com/android/2014/06/24/adb-wir ...

  5. cocos2d-x3.0rc 版 设置模拟器窗体大小

    由于刚接触这职业时间不是非常长.也是第一次写博客,假设有错误的地方还请大神们指出,开通这博客目的非常easy相互学习和讨论(更重要的是记录工作中学到的东西以方便以后自己查阅) 先后參与过两个项目.只是 ...

  6. 采用SharePoint Designer将JavaScript而他们的网站页面集成的定义

    采用SharePoint Designer将JavaScript而他们的网站页面集成的定义 像JavaScript这种动态脚本语言可以给你的页面震撼效果.为了加盟JavaScript要定义自己的网站页 ...

  7. Docker镜像与容器命令(转)

    Docker是一个开源的引擎,可以轻松的为任何应用创建一个轻量级的.可移植的.自给自足的容器.开发者在笔记本上编译测试通过的容器可以批量地在生产环境中部署,包括VMs(虚拟机).bare metal. ...

  8. 【原创】只学到二维数组和结构体,不用链表也能写一个C贪食蛇?(四)

    全系列Index: [原创]只学到二维数组和结构体,不用链表也能写一个C贪食蛇?(一) [原创]只学到二维数组和结构体,不用链表也能写一个C贪食蛇?(二) [原创]只学到二维数组和结构体,不用链表也能 ...

  9. 从控制台读取password - C#

    Tip :    从控制台读取password 语言: C# ______________________________________________________________ 在登陆Lin ...

  10. sails 相关文章

    Node 框架之sails   http://cnodejs.org/topic/555c3c82e684c4c8088a0ca1