재우니의 블로그

test.html


javascript 로 로딩바 만들어 보기


<!DOCTYPE html>
<html>
<style>
    #myProgress {
    position: relative;
    width: 100%;
    height: 30px;
    background-color: #ddd;
    }

    #myBar {
    position: absolute;
    width: 1%;
    height: 100%;
    background-color: #4CAF50;
    }
    </style>
<body>

<h1>프로그래스바</h1>

<div id="myProgress">
  <div id="myBar"></div>
</div>

<br>
<button onclick="move()">은주맴 누르삼</button> 

<script>
    function move() {
        var elem = document.getElementById("myBar");   
        var width = 1;
        var id = setInterval(frame, 1000);
        function frame() {
            if (width >= 100) {
                clearInterval(id);
            } else {
                width++; 
                elem.style.width = width + '%'; 
                elem.innerText = width + '%'; 
            }
        }
    }
</script>

</body>
</html>