<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. 虚拟化技术学习(一)在VMware虚拟机中安装KVM

    近期一直研究虚拟化技术,曾经对VMware虚拟机有一定的了解,近期突发奇想,能不能在VMware虚拟机中再装一个虚拟机呢? 那么问题就来了,首先,你须要一台电脑,vmware软件,(本人的电脑配置渣渣 ...

  2. linux提取锁和信号灯经常使用

    1.信号( 这两个过程之间的同步) struct semaphore power_sem; sema_init(&pdata->power_sem,1); down(&pdata ...

  3. poj 3101 Astronomy(分数的最小公倍数)

    http://poj.org/problem? id=3101 大致题意:求n个运动周期不全然同样的天体在一条直线上的周期. 这题我是看解题报告写的,没想到选用參照物,用到了物理中的角速度什么的. 由 ...

  4. altKey,ctrlKey,shiftKey

    <1> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>< ...

  5. windows下cocos2dx3.0开发环境及Android编译环境搭建

    cocos2dx更新到了3.x版本号,自己一直没有换,如今开发组要求统一换版本号,我就把搭建好开发环境的过程记录下来. 一.Windowns下开发环境搭建 1.  所需工具         1)coc ...

  6. [背景分离] 识别移动物体基于高斯混合 MOG

    使用很easy,  frame 就是当前帧,  foreground 是取得的, binary 型背景, 0.03是学习速率能够依据实际调整. cv::BackgroundSubtractorMOG ...

  7. PHP图像处理:3D图纸、缩放、回转、剪下、水印(三)

    来源:http://www.ido321.com/887.html 5.PHP对图像的旋转 1: <div> 2: <h4>旋转之前</h4> 3: <img ...

  8. Javadoc的Html文件传输chm

     Javadoc的Html文件转chm 工具下载地址:http://msdn.microsoft.com/en-us/library/ms669985.aspx 两篇相关文章: MyEclipse ...

  9. 使用JAVASCRIPT实现静态物体、静态方法和静态属性

    Javascript语言的面向对象特征非常弱.其它面向对象语言在创建类时仅仅要使用keywordstatic就可以指定类为静态类,Javascript没有提供static这种keyword.要让Jav ...

  10. Word001

    C# Word 类库 2009-08-06 22:10 13470人阅读 评论(10) 收藏 举报 c#objectstring文档microsoftexcel using System;using ...