其他分享
首页 > 其他分享> > 运动六 --- 训练逻辑思维第六步

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

作者:互联网

//获取非行内样式
function getStyle(obj,attr){
return obj.currentStyle ? obj.currentStyle[attr] : getComputedStyle(obj,1)[attr];

}
//运动框架
function sport_06(obj,attr,target){
//1.清除上一次的计时器
clearInterval(obj.timer);
//2. 开启新的计时器
obj.timer = setInterval(function(){
//1. 获取当前值
let cur = attr === ‘opacity’ ? parseInt(parseFloat(getStyle(obj,attr)) * 100) : parseInt(getStyle(obj,attr));
//2. 计算速度
let speed = (target - cur) / 8;
//3. 检测停止
if(cur === target){
clearInterval(obj.timer);
}else{
if(attr === ‘opacity’){
obj.style.opacity = (cur + speed) / 100;
obj.style.filter = ‘alpha(opacity’ + (cur + speed) +’)’;
}else{
obj.style[attr] = cur + speed + ‘px’;
}
}
},30)
}

标签:opacity,style,obj,cur,训练,逻辑思维,speed,第六步,attr
来源: https://blog.csdn.net/weixin_45052104/article/details/91284312