<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <style> #someDiv{ width: 300px; height: 300px; background-color: aqua; opacity: 1; } </style> <body> <div id="someDiv"></div> <script> var div =document.getElementById("somerDiv"); var opacity =1; var fade =setInterval(function(){ opacity-=0.05; if(opacity >0){ div.style.opacity=opacity; }else{ clearInterval(fade) } },60) </script> </body> </html>
运行不了