JS inside about the movement of the framework is more, starting from the basic, I feel that the buffer movement is more important than the teaching basis, first provide a small example.
<script type= "Text/javascript" >
Window.onload = function ()
{
var obtn = document.getElementById ("btn1");
var odiv = document.getElementById ("Div1"); Get div by ID
Obtn.onclick = function ()
{
Startmove (310); Set the target value, both the location to reach
}
function Startmove (itarget)//Incoming target value, movement to where
{
Clearinterval (timer); Before opening a timer, first initialize, clear the open, to avoid the impact
var timer = null;
Timer = setinterval (function () {
var ispeed = (itarget-odiv.offsetleft)/10; Before you use offsetleft, you need to position the operand with a LETF value
Ispeed = ispeed>0? Math.ceil (ispeed): Math.floor (Ispeed);
General If,else statements can be written as three-mesh operators
if (ispeed>0) {
Ispeed = Math.ceil (ispeed); Rounding up so that the movement speed is rounded so that the operand stops before it reaches the target.
}else{
Ispeed = Math.floor (ispeed); Rounding down
// }
if (odiv.offsetleft==itarget)
{
Clearinterval (timer);
}else
{
ODiv.style.left = odiv.offsetleft + ispeed + ' px ';
}
Document.title = ODiv.style.left;
},30);
};
};
</script>
This is about the buffer movement more practical ideas, should also be in the future, the most important thing is to understand the relationship between the target value and speed
Notes on JavaScript buffered motion