Home > Web Front-end > JS Tutorial > JavaScript animation effect class encapsulation code_javascript skills

JavaScript animation effect class encapsulation code_javascript skills

WBOY
Release: 2016-05-16 19:09:38
Original
1018 people have browsed it








 <br>output1是改变value <br>output1是改变宽度 <br>output3是淡入 <br>output4是带缓动的宽度 <br>
Copy after login

<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>
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template