javascript定时函数 单次定时做滚动条
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>JavaScript</title> <style> #outBox{ width:600px; height:30px; border:1px solid #333; } #inBox{ background-color:#abcdef; height:30px; width:0%; } </style> </head> <body> <h1>定时函数 单次定时做滚动条</h1> <hr> <div id="outBox"> <div id="inBox"></div> </div> <script> //setInterval clearInterval //setTimeout clearTimeout setTimeout(function(){ //alert('ok'); }, 2000); //获取div var inBox = document.getElementById('inBox'); var m = 0; function run(){ inBox.style.width = m+'%'; m ++; if (m > 100) { return; } setTimeout(run, 100); } run(); </script> </body> </html>