不断在控制台输出数字

var i = 0;

setInterval(function(){

  i++;
console.log(i);

},1000)

元素透明度渐变效果

<!DOCTYPE html>
<html lang="zh">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>

  <style>

#someDiv{

  width:100px;
  height:100px;
  background-color:red;
  opacity:1;

}





  </style>

</head>
<body>
  
  


<div id="someDiv"></div>












<script>



var div = document.getElementById("someDiv");

var opacity = 1;

var fade = setInterval(function(){
if(opacity>0){

  opacity -= 0.05;

div.style.opacity = opacity;

}else{

  clearInterval(fade)

};

},1000);








</script>






</body>
</html>