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

let timer = null;
let alpha = 100;
function sport_03(obj,target){
clearInterval(timer);
timer = setInterval(()=>{
let speed = (target - alpha) / 8; //基数
speed = speed > 0 ? Math.ceil(speed) : Math.floor(speed);
if(alpha === target){
clearInterval(timer);
}else{
alpha += speed;
obj.style.opacity = alpha / 100;
obj.style.filter = ‘alpha(opacity’ + alpha +’)’;
}
console.log(obj.style.opacity);
},30)
}

猜你喜欢

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