JavaScript "Perfect Motion frame"

Source: Internet
Author: User

/*the "Perfect motion frame", the so-called "perfect", is a motion function move () that can achieve multiple parameters, and the movement of multiple objects does not affect each other. * The approximate structure is as follows: Motion frame Exp:move (obj,{width:200,height:200},fnend) * obj: Moving object * JSON: A JSON collection of motion properties and moving target values {' Width ': 2 XX, ' height ': $} * SV: Movement speed, speed-value, the smaller the value the greater the speed * Fnend: callback function after the end of the movement*/functionMove (obj, JSON, SV, fnend) {//take CSS style values    functionGetStyle (obj, attr) {if(obj.currentstyle) {returnObj.currentstyle[attr]; } Else {                returngetComputedStyle (obj,false) [attr]; }        }        //movement beginsclearinterval (Obj.timer); Obj.timer= SetInterval (function() {        varisallcompleted =true;//Assuming all the movement is complete.         for(attrinchJSON) {            varAttrValue = 0; Switch(attr) { Case' Opacity ': AttrValue= Math.Round (parsefloat (GetStyle (obj, attr)) * 100);  Break; default: AttrValue=parseint (GetStyle (obj, attr)); }            //4 If no SV is passed in            varSpeed = (json[attr]-attrValue)/(SV | | 4); speed= Speed > 0?Math.ceil (Speed): Math.floor (speed); //If there is an unfinished movement in the loop, the isallcompleted is False            if(AttrValue! = json[attr]) isallcompleted =false; Switch(attr) { Case' Opacity ': {obj.style.filter= "Alpha (opacity=" + (AttrValue + speed) + ")"; Obj.style.opacity= (AttrValue + speed)/100;                    };  Break; default: obj.style[attr]= AttrValue + speed + ' px '; }        } //For in end!        //after all loops are completed, the timer is only turned off when all movements have ended (isallcompleted=true)        if(isallcompleted) {clearinterval (Obj.timer); if(Fnend) fnend (); }    }, 30);} //move () end!

From

JavaScript "Perfect Motion frame"

Related Article

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.