天天看点

div逐渐透明化

<!DOCTYPE html>
<html >
<head>
  <meta charset="UTF-8">
  <title>title</title>
  <style>
    div{
      width: 300px;
      height: 200px;
      background-color: hotpink;

    }
  </style>
</head>
<body>

<div id="dv"></div>
<input type="button" value="渐变" id="btn"/>
<script src="common.js"></script>
<script>


  my$("btn").onclick=function () {

    var opacity=1;
    //按钮的点击事件
    var timeId=setInterval(function () {
      //透明化了
      opacity=opacity-0.1;
      if(opacity<=0){
        clearInterval(timeId);//清理定时器
      }
      //设置div的透明度
      my$("dv").style.opacity=opacity;
    },200);


  };












</script>
</body>
</html>
           

继续阅读