Single-Attribute buffered motion
1 /**2 * Single-Attribute buffered motion3 */4 functionFnsinglebuffermove (ODom, sattr, ITarget, fn) {5 varispeed, icur;6 clearinterval (odom.timer);7Odom.timer = SetInterval (function(){8 //Calculate Current Value9 if(sattr = = ' opacity '){TenIcur = Math.Round (Fngetstyle (ODom, sattr) * 100); One}Else{ AIcur =parseint (Fngetstyle (ODom, sattr)); - } - the //Calculation Speed -Ispeed = (itarget-icur)/8; -Ispeed = ispeed > 0? Math.ceil (ispeed): Math.floor (Ispeed);//Speed Rounding (the browser rounds the decimal part of the style, resulting in a failure to reach the end point) - + //Motion Stop - if(Icur = =itarget) { + clearinterval (odom.timer); AFN &&fn (); at}Else{ - if(sattr = = ' opacity '){ -ODom.style.opacity = (icur + ispeed)/100; -ODom.style.filter = ' alpha (opacity: ' + (Icur + ispeed) + ') '; -}Else{ -ODOM.STYLE[SATTR] = icur + ispeed + ' px '; in } - } to}, 30); +}
Multi-attribute Buffered motion
1 /**2 * Multi-attribute buffering motion3 */4 functionFnmultibuffermove (ODom, JSON, FN) {5 varispeed, Icur, bstop;6 clearinterval (odom.timer);7Odom.timer = SetInterval (function(){8Bstop =true;9 for(varSattrinchJSON) {Ten //Calculate Current Value One if(sattr = = ' opacity '){ AIcur = Math.Round (Fngetstyle (ODom, sattr) * 100); -}Else{ -Icur =parseint (Fngetstyle (ODom, sattr)); the } - - //Calculation Speed -Ispeed = (json[sattr]-icur)/8; +Ispeed = ispeed > 0? Math.ceil (ispeed): Math.floor (Ispeed);//Speed Rounding (the browser rounds the decimal part of the style, resulting in a failure to reach the end point) - + //Sports A if(Icur! =Json[sattr]) { atBstop =false; - if(sattr = = ' opacity '){ -ODom.style.opacity = (icur + ispeed)/100; -ODom.style.filter = ' alpha (opacity: ' + (Icur + ispeed) + ') '; -}Else{ -ODOM.STYLE[SATTR] = icur + ispeed + ' px '; in } - } to } + - //Motion Stop the if(bstop) { * clearinterval (odom.timer); $FN &&fn ();Panax Notoginseng } -}, 30); the}
The buffering motion of JS Motion Foundation