--- training exercise three logical thinking Step

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)
}

Guess you like

Origin blog.csdn.net/weixin_45052104/article/details/91283656