Perfect motion Frame

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.