1. Uniform Motion
1 /**2 * @param obj-object to be changed3 * @param json-List of properties to be changed4 * @return func-Chained call5 */6 functionstartmove (obj, JSON, func) {7 //clear the previous timer8 clearinterval (obj.timer);9 Ten //Turn on Timer OneObj.timer = SetInterval (function() { A //detects if all animations have completed the identity - varBstop =true; - the //Loop through all the properties to be changed - for(varattrinchJSON) { - varicur = 0;//Current Value - varITarget = json[attr];//target value + - if(attr = = = "Opacity") { +Icur = parsefloat (GetStyle (obj, attr)) * 100; A}Else { atIcur =parseint (GetStyle (obj, attr)); - } - - //Uniform Motion - varIspeed = 10; - in if(Icur!==itarget) { - //do not stop the timer as long as one animation is not completed toBstop =false; + - //Temporary Results the vartemp =ITarget; * $ //prevent final cross-border processingPanax Notoginseng if(Ispeed < Math.Abs (Icur-itarget)) { -temp = Icur +Ispeed; the } + A if(attr = = = "Opacity") { theObj.style.filter = "Alpha (opacity:" + temp + ")" +Obj.style.opacity = temp/100; -}Else { $OBJ.STYLE[ATTR] = temp + "px"; $ } - } - } the - //If all animations are complete, clear the timerWuyi if(bstop) { the clearinterval (obj.timer); - Wu //chain call to perform the action after the animation is completed - if(func) { About func (); $ } - } -}, 30); - } A + //compatible, get object style the functionGetStyle (obj, attr) { - if(obj.currentstyle) { $ returnobj.currentstyle[attr]; the}Else { the returngetComputedStyle (obj,false) [attr]; the } the}
2. Cushioning (deceleration) movement
1 /**2 * @param obj-object to be changed3 * @param json-List of properties to be changed4 * @return func-Chained call5 */6 functionstartmove (obj, JSON, func) {7 //clear the previous timer8 clearinterval (obj.timer);9 Ten //Turn on Timer OneObj.timer = SetInterval (function() { A //detects if all animations have completed the identity - varBstop =true; - the //Loop through all the properties to be changed - for(varattrinchJSON) { - varicur = 0;//Current Value - varITarget = json[attr];//target value + - if(attr = = = "Opacity") { +Icur = parsefloat (GetStyle (obj, attr)) * 100; A}Else { atIcur =parseint (GetStyle (obj, attr)); - } - - //deceleration (cushioning) motion - varIspeed = (itarget-icur)/8; - in //prevent decimals from causing errors -Ispeed = ispeed > 0?Math.ceil (ispeed): Math.floor (ispeed); to + if(Icur!==itarget) { - //do not stop the timer as long as one animation is not completed theBstop =false; * $ if(attr = = = "Opacity") {Panax NotoginsengObj.style.filter = "Alpha (opacity:" + icur + ispeed + ")" -Obj.style.opacity = (icur + ispeed)/100; the}Else { +OBJ.STYLE[ATTR] = icur + ispeed + "px"; A } the } + } - $ //If all animations are complete, clear the timer $ if(bstop) { - clearinterval (obj.timer); - the //chain call to perform the action after the animation is completed - if(func) {Wuyi func (); the } - } Wu}, 30); - } About $ //compatible, get object style - functionGetStyle (obj, attr) { - if(obj.currentstyle) { - returnobj.currentstyle[attr]; A}Else { + returngetComputedStyle (obj,false) [attr]; the } -}
Perfect motion Frame