The Motion frame buffer Motion of js
Because the numeric decimal point in JS is automatically removed, for the motion position, you need to use Math.ceil () to round up or
Math.floor () rounding down to solve the problem
Here is my simple code for buffering exercise
Untitled document # div1 {width:200px;height:200px;background:red;left:0px;top:50px;position:absolute;} # div2 {width:1px;height:250px;background:black;left:400px;top:20px;position:absolute;} _ window.onload=function () {var oDiv=document.getElementById ('div1'); var oBtn=document.getElementById (' btn1'); oBtn.onclick=function () {startMove }}; var timer=null;function startMove (target) {var oDiv=document.getElementById ('div1'); var speed=0 ClearInterval (timer) timer=setInterval (function () {/ / speed will be rounded directly and the remainder will be rounded off, so the position is not accurate, so we need to solve speed=Math.ceil ((target-oDiv.offsetLeft) / 10) by rounding up Math.ceil (); oDiv.style.left=oDiv.offsetLeft+speed+'px' Document.title=oDiv.offsetLeft+','+speed;}, 30);}