zoukankan
html css js c++ java
测试运行框
tween算法,顺便测试一下运行框,都是偷来的。生存需要!
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8"> <title></title> <style type="text/css"> #div1 { 50px; height: 50px; background: #ccc;position: relative;} </style> </head> <body> <div id="div1" onclick="Run();"></div> </body> </html> <script type="text/javascript"> 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: { 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: { 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: { easeIn: function(t,b,c,d,a,p){ if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.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; }, easeOut: function(t,b,c,d,a,p){ if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.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); }, easeInOut: function(t,b,c,d,a,p){ if (t==0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(.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 -.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: { easeIn: function(t,b,c,d,s){ if (s == undefined) s = 1.70158; return c*(t/=d)*t*((s+1)*t - s) + b; }, easeOut: function(t,b,c,d,s){ if (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 (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: { 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; } } } var b=50,c=100,d=100,t=0; function Run(){ var div = document.getElementById("div1"); div.style.left = Math.ceil(Tween.Bounce.easeOut(t,b,c,d)) + "px"; if(t<d){ t++; setTimeout(Run, 10); } } </script>
运行代码
这个算法是在其他博客上看的,从flash上取的算法。稍微改一下就可以用到JS上了,感谢这些写出来的人啊。
查看全文
相关阅读:
WinAPI: DrawFrameControl 绘制控件
WinAPI: SetPixel 和 SetPixelV 设置设备环境中指定位置的颜色
WinAPI: GetSystemInfo 获取系统信息
WinAPI: GetDiskFreeSpace 获取磁盘组织与容量信息
WinAPI: GetDiskFreeSpaceEx 获取磁盘容量信息
分享:Afinal 0.3.5 发布,Android快速开发框架
海量数据多路归并排序的c++实现(归并时利用了败者树)
当TransferEncoding遇上ContentEncoding_虚拟现实_百度空间
chunked 编码 解码 c算法 yaneng的专栏 博客频道 CSDN.NET
败者树 多路平衡归并外部排序 Dreaming.O的专栏 博客频道 CSDN.NET
原文地址:https://www.cnblogs.com/coolicer/p/2037678.html
最新文章
函数04 零基础入门学习C语言35
函数05 零基础入门学习C语言36
[BX]和loop指令06 零基础入门学习汇编语言28
[BX]和loop指令04 零基础入门学习汇编语言26
VC++分析数据包实现UDP协议分析
VC++分析数据包实现分析http协议
VC++分析数据包实现FTP协议分析
真实世界的Windows Azure:使用Windows Azure社交游戏开发商享有更低的成本和改进的扩展性
VC++实现ip数据包分析
VC++分析数据包实现TCP协议的分析
热门文章
Windows Azure HDInsight 服务入门
云操作系统正离中国越来越近
那些消失的计算机技术(一)
VC++分析数据包实现ICMP协议分析
大学生职业定位
WinAPI: GetDriveType 获取磁盘类型
WinAPI: GetVolumeInformation 读取文件系统信息
WinAPI: GetLogicalDrives 判断系统中存在的逻辑驱动器
WinAPI: CopyFile 复制文件
WinAPI: GetKeyboardType 获取键盘的类型信息
Copyright © 2011-2022 走看看