The buffered motion of JS, often used for carousel
<! DOCTYPE html>#box {width:100px; height:100px; Background:skyblue; Position:absolute; } </style>varOBox = document.getElementById ("box"); Startmove (OBox, {left:500},function() {Startmove (OBox, {top:500}) }); //you can get a non-inline style functionGetStyle (obj, attr) {returnObj.currentstyle? OBJ.CURRENTSTYLE[ATTR]: getComputedStyle (obj,NULL) [attr]; }functionstartmove (obj, JSON, fn) {//clears the timer, avoids multiple calls and causes the timer to perform Chaosclearinterval (Obj.timer); Obj.timer= SetInterval (function(){ for(attrinchJSON) { varIcur = 0; //attr If it is opacity, consider the compatible wording of IEIcur = (attr = = ' opacity ')? Math.Round (GetStyle (obj, attr) * 100): parseint (GetStyle (obj, attr)); //ispeed is a growth variable, the divisor can be seen by the situation change varIspeed = (json[attr]-icur)/50;//do not understand why Ispeed is greater than 0 rounding up, less than 0 down rounding, may not let Ispeed equals 0Ispeed = ispeed > 0?Math.ceil (ispeed): Math.floor (Ispeed); //Change Style if(attr = = ' opacity ') {Obj.style.filter= "Alpha (opacity:" + (Icur+ispeed) + ")"; Obj.style.opacity= (icur+ispeed)/100; }Else{obj.style[attr]= icur + ispeed + ' px '; }//when the value of the style corresponds to the target value, clear the timer, and if there is a callback function that defines FN, execute if(Icur = =Json[attr]) {clearinterval (Obj.timer); FN&&fn (); } } }, 10) } </script></body>
JS Buffered Motion