初学javascript的参考例子
<!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8"> <title></title> <style> body{ margin: 0px; padding: 0px; } #d{ width: 0px; height: 100px; background-color: #4736ff; } </style> </head> <body> <div id="d"></div> <script> (function(){ var div=document.getElementById("d"); var show=function(){ div.style.width=(div.offsetWidth+1)+"px"; if(div.offsetWidth==400){ clearInterval(interval); } }; interval=setInterval(show,10); })() </script> </body> </html>