Move.js
functionGetStyle (obj, name) {returnObj.currentstyle?obj.currentstyle[name]:getcomputedstyle (obj,false) [name];};functionMove (obj, JSON, options) {Options=options| |{}; Options.type=options.type| | ' Buffer; Options.time=options.time| | 700; varCount=parseint (OPTIONS.TIME/30);varN=0; varstart={}; vardis={}; for(varNameinchJSON) { if(name== ' opacity ') {Start[name]=math.round (parsefloat (GetStyle (obj, name)) *100); }Else{Start[name]=parseint (GetStyle (obj, name)); }; Dis[name]=json[name]-Start[name]; }; Clearinterval (Obj.timer); Obj.timer=setinterval (function() {n++; for(varNameinchJSON) { Switch(options.type) { Case' Linear '://constant Speed varCur=start[name]+dis[name]*n/count; Break; Case' Buffer '://Buffering varA=1-n/count;varcur=start[name]+dis[name]* (1-a*a*a); Break; Case' Ease-in '://Acceleration varA=n/count;varcur=start[name]+dis[name]* (a*a*a); Break; }; if(name== ' opacity ') {Obj.style.filter= ' Alpha (opacity: ' +cur+ ') '; Obj.style.opacity=cur/100; }Else{Obj.style[name]=cur+ ' px '; }; }; if(n==count) {clearinterval (Obj.timer); Options.end&&Options.end (); }; }, 30);}
Calling methods
<!DOCTYPE HTML><HTMLLang= "en"><Head> <MetaCharSet= "UTF-8"> <title>Document</title> <style>#div1{width:200px;Height:200px;background:Red;position:Absolute; Left:0;Top:20px;} </style></Head><Body> <DivID= "Div1"></Div> <Scriptsrc= "Move.js"></Script> <Script>window.onload= function(){ varOdiv=document.getElementById ('Div1'); Odiv.onclick= function() {Move ( This, {left: -, Top: -, opacity:Ten}, {time: the, type:'Buffer', End:function() {alert (1); }}); }; }; </Script></Body></HTML>
JS Motion components, Move.js