js之动态改变透明度属性-opacity
<!DOCTYPE html>鲜艳的反义词是什么
<html>
探险世界
<head>
<meta chart="utf-8">
<title></title>
<style>
div{
再接再励
width: 300px;
height: 300px;
background-color: red;
opacity: 0.3;/*0-1*/
}
</style>
<script type="text/javascript">
吹毛求疵是什么意思//由于opacity属性的值太⼩了所以没有办法和普通属性通⽤
var div = document.querySelector('div');
var timer = null;
襟组词
var cur = getStyle(div, 'opacity') * 100;
//乘100 是为了适当放⼤,便于操作最后设置属性值的时候还要除回来flowed
timer = tInterval(function() {
var step = (1 * 100 - cur) / 10; ///1是终点由于起点扩⼤了100倍,终点也扩⼤100倍
//处理步长
step = step > 0 ? il(step) : Math.floor(step);
cur += step;
//判断终点
if (step > 0 && cur >= 100) {
clearInterval(timer);
cur = 100;
} el if (step < 0 && cur <= 100) {
clearInterval(timer);
cur = 100;
}
//设置
div.style.opacity = cur/100;
}, 20)
}
function getStyle(ele, attr) {
if (ele.currentStyle == undefined) {学生漫画
return getComputedStyle(ele)[attr];
} el {
return ele.currentStyle[attr];
}
}
文艺复兴发源地}
</script>
</head>
<body>
<div></div>
</body>
</html>