首页 web前端 js教程 javascript动画效果类封装代码_javascript技巧

javascript动画效果类封装代码_javascript技巧

May 16, 2016 pm 07:09 PM








<script> <BR>function Animation(target,targetProperty,closure,precision) <BR>{ <BR> closure=closure||function(x){return x;}; <BR> precision=precision||10; <BR> this.handle; <br><br> var beginTime=new Date(); <BR> var stopTime=new Date(); <BR> this.Begin=function(){ <BR> beginTime=new Date(); <BR> this.handle=setInterval( <BR> function(){ <BR> var now=new Date(); <BR> target[targetProperty]=closure(now.getTime()-beginTime.getTime()); <BR> }, <BR> precision <BR> ); <BR> } <br><br> this.Continue=function(){ <BR> var now=new Date(); <BR> beginTime.setTime(now.getTime()-stopTime.getTime()+beginTime.getTime()); <br><br> this.handle=setInterval( <BR> function(){ <BR> var now=new Date(); <BR> target[targetProperty]=closure(now.getTime()-beginTime.getTime()); <BR> }, <BR> precision <BR> ); <BR> } <br><br> this.Stop=function(duration){ <br><br> clearInterval(this.handle); <br><br> if(duration===undefined) <BR> { <BR> stopTime=new Date(); <BR> duration=stopTime.getTime()-beginTime.getTime(); <BR> } <BR> else stopTime.setTime(beginTime.getTime()+duration) <BR> target[targetProperty]=closure(duration); <BR> } <BR>} <br><br>function StoryBoard(Duration,onfinish,flag) <BR>{ <BR> onfinish=onfinish||function(){}; <BR> var r=new Array(); <BR> r.appendAnimation=function(animation) <BR> { <BR> if(animation instanceof Animation) <BR> this.push(animation); <BR> } <BR> r.removeAnimation=function(animation) <BR> { <BR> for(var i=0;i<r.length;i++) <BR> { <BR> if(r[i]==animation) <BR> { <BR> r.splice(i,1); <BR> break; <BR> } <BR> } <BR> } <BR> r.start=function(){ <BR> for(var i=0;i<r.length;i++) <BR> { <BR> r[i].Begin(); <BR> } <BR> setTimeout( <BR> function(){ <BR> for(var i=0;i<r.length;i++) <BR> { <BR> r[i].Stop(Duration); <BR> } <BR> }, <BR> Duration <BR> ); <BR> onfinish(); <BR> } <BR> return r; <br><br>} <BR>//////////////////////////////下面是使用方法//////////////////////////////// <BR>function $(id) <BR>{ <BR> return document.getElementById(id); <BR>} <BR>var a1=new Animation($("output1"),"value"); <BR>var a2=new Animation($("output2"),"width",function(x){return Math.floor(x/10);}); <BR>var a3=new Animation($("output3").style,"filter",function(x){return "alpha(opacity="+Math.floor(x/5000*100)+")";}); <BR>var a4=new Animation($("output4").style,"width",function(x){return Math.floor(x*x*x/50000/5000)+"px";}); <BR>var s=new StoryBoard(5000); <BR>s.appendAnimation(a1); <BR>s.appendAnimation(a2); <BR>s.appendAnimation(a3); <BR>s.appendAnimation(a4); <BR>s.start(); <br><br></script>
 <br>output1是改变value <br>output1是改变宽度 <br>output3是淡入 <br>output4是带缓动的宽度 <br>
登录后复制

本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热门文章

仓库:如何复兴队友
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热门文章

仓库:如何复兴队友
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶体解释及其做什么(黄色晶体)
1 周前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒险:如何获得巨型种子
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热门文章标签

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

在JavaScript中替换字符串字符 在JavaScript中替换字符串字符 Mar 11, 2025 am 12:07 AM

在JavaScript中替换字符串字符

自定义Google搜索API设置教程 自定义Google搜索API设置教程 Mar 04, 2025 am 01:06 AM

自定义Google搜索API设置教程

示例颜色json文件 示例颜色json文件 Mar 03, 2025 am 12:35 AM

示例颜色json文件

8令人惊叹的jQuery页面布局插件 8令人惊叹的jQuery页面布局插件 Mar 06, 2025 am 12:48 AM

8令人惊叹的jQuery页面布局插件

构建您自己的Ajax Web应用程序 构建您自己的Ajax Web应用程序 Mar 09, 2025 am 12:11 AM

构建您自己的Ajax Web应用程序

什么是这个&#x27;在JavaScript? 什么是这个&#x27;在JavaScript? Mar 04, 2025 am 01:15 AM

什么是这个&#x27;在JavaScript?

通过来源查看器提高您的jQuery知识 通过来源查看器提高您的jQuery知识 Mar 05, 2025 am 12:54 AM

通过来源查看器提高您的jQuery知识

10张移动秘籍用于移动开发 10张移动秘籍用于移动开发 Mar 05, 2025 am 12:43 AM

10张移动秘籍用于移动开发

See all articles