div计时器渐变/淡入淡出
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>title</title>
<style>
div{
width: 300px;
height: 200px;
background-color: hotpink;
}
</style>
</head>
<body>
<div id="div"></div>
<input type="button" value="渐变" id="btn"/>
<script>
document.getElementById("btn").onclick=function () {
var opacity=10;
var timeId=setInterval(function () {
opacity--;
if(opacity<=0){
clearInterval(timeId);
}
document.getElementById("div").style.opacity=opacity/10;
},200);
};
</script>
</body>
</html>