Search

_0503_속도중첩_미해결

대분류
STEP05 비동기
소분류
비동기

영상

개념

<!DOCTYPE html> <html lang="ko"> <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> <style> #bar { width: 100%; height: 30px; background-color: lightgray; } #progress { width: 10px; height: 30px; background-color: yellowgreen; } </style> </head> <body> <div id="bar"> <div id="progress"></div> </div> <button onclick="progressFunction()">시작</button> <script> let width = 0; let id = null; function progressFunction() { width = 0; id = setInterval(move, 50); } function move() { let element = document.getElementById("progress"); if(width == 100) { clearInterval(id); } else { width++; element.style.width = width + "%"; } console.log(width); } </script> </body> </html>
Java
복사