I'm

Developer, Designer, Photographer

GET IN TOUCH

  • Buk-gu, Busan, Republic of Korea
  • ungdoli0916@naver.com
  • Kakao ID : Ungdoli
Your message has been sent. Thank you!
(즐거웅코드) 자바스크립트 단순한 progressbar 구현하기

· 즐거'웅' 코드 (Source)/HTML & CSS & JAVASCRIPT
2021. 9. 21. 20:12

반응형

[즐거'웅'코드] 목차

  1. 예제 소스
  2. 구현 예시
예제 소스
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<style>
    #progress-container {
        width: 100%;
        background-color: #DDDDDD;
    }
 
    #progress-bar {
        width: 0;
        height: 30px;
        line-height: 30px;
        background-color: #8C9CEC;
        text-align: center;
    }
</style>
 
<div id="progress-container">
    <div id="progress-bar"></div>
</div>
<br>
<button onclick="start()">progress</button>
 
<script>
    var i = 0;
 
    function start() {
        if (i == 0) {
            i = 1;
            var elem = document.getElementById("progress-bar");
            var width = 0;
            var id = setInterval(frame, 10);
 
            function frame() {
                if (width >= 100) {
                    clearInterval(id);
                    i = 0;
                } else {
                    width++;
                    elem.style.width = width + "%";
                    elem.innerHTML = width + "%";
                }
            }
        }
    }
</script>
구현 예시
반응형