运动一 ----- 训练逻辑思维第一步

let timer = null;
function sport_01(obj,target){
clearInterval(timer);
timer = setInterval(()=>{
let speed = target > obj.offsetLeft ? 7 : -7;
if(Math.abs(target - obj.offsetLeft) < Math.abs(speed)){
clearInterval(timer);
obj.style.left = target + ‘px’;
}else{
obj.style.left = obj.offsetLeft + speed + ‘px’;
}
},30)
}

猜你喜欢

转载自blog.csdn.net/weixin_45052104/article/details/91283044
今日推荐