关于Math.ceil和Math.floor
<script>
window.onload = function(){
var oDIV = document.getElementById('move');
oDIV.onmouseover = function(){
move(0);
}
oDIV.onmouseout = function(){
move(-200);
}
}
var si=null
function move(iTarget){
clearInterval(si);
var oDIV = document.getElementById('move');
si=setInterval(function(){
var speed=0.6;//当speed小于或等于0.5 div只移动一次
//speed=speed>0?Math.ceil(speed):Math.floor(speed);
if(oDIV.offsetLeft == iTarget){
clearInterval(si);
}else{
oDIV.style.left = oDIV.offsetLeft+speed+"px";
}
},30);
}
</script>为什么当speed小于或等于0.5 div只移动一次,求老师或者大神解答。是因为left属性四舍五入了吗?