一、三個(gè)取整函數(shù)
- 數(shù)學(xué)函數(shù) Math
- Math.ceil() 向上取整耕拷,取大的
console.log(Math.ceil(1.01)) 結(jié)果 是 2
console.log(Math.ceil(1.9)) 結(jié)果 2
console.log(Math.ceil(-1.3)) 結(jié)果 是 -1 - Math.floor() 向下取整,取小的
console.log(Math.floor(1.01)) 結(jié)果 是 1
console.log(Math.floor(1.9)) 結(jié)果 1
console.log(Math.floor(-1.3)) 結(jié)果 是 -2 - Math.round() 四舍五入函數(shù)
console.log(Math.round(1.01)) 結(jié)果 是 1
console.log(Math.round(1.9)) 結(jié)果 是 2
二、緩動(dòng)動(dòng)畫原理
1.勻速:原來(lái)位置+步長(zhǎng)
2.歡動(dòng):原來(lái)位置+步長(zhǎng)(變化的)
var step = (target - obj.offsetLeft) / 10;
var timer = null;
var target = 400;
$("btn200").onclick = function(){
timer = setInterval(function(){
var step = (target - $("box").offsetLeft)/10;
step = step>0?Math.ceil(step):Math.floor(step);
box.style.left = $("box").offsetLeft + step +"px";
if($("box").offsetLeft == target){
clearInterval(timer);
}
},30);
}