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!
(즐거웅코드) 제이쿼리 목표 그래프(가로형) 구현하기

· 즐거'웅' 코드 (Source)/HTML & CSS & JAVASCRIPT
2021. 6. 15. 17: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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
 
<style>
    .test_obj {
        background-color: rgba(0, 0, 0, .1);
        color: #fff;
        font-size: 15px;
        line-height: 50px;
        height: 50px;
        margin-bottom: 10px;
        border-radius: 25px;
    }
 
    .test_obj * {
        transition: all 1s ease;
    }
 
    .test_obj div {
        background: linear-gradient(to right, #fc466b 0%, #3f5efb 100%);
        position: relative;
        width: 0;
        border-radius: 25px;
    }
 
    .test_obj span:first-child {
        padding-left: 15px;
    }
 
    .test_obj span:last-child {
        position: absolute;
        right: 15px;
    }
</style>
 
<div>
    <div class="test_obj">
        <div data-width="70">
            <span>목표 1</span>
            <span>70%</span>
        </div>
    </div>
    <div class="test_obj">
        <div data-width="100">
            <span>목표 2</span>
            <span>100%</span>
        </div>
    </div>
    <div class="test_obj">
        <div data-width="95">
            <span>목표 3</span>
            <span>95%</span>
        </div>
    </div>
</div>
 
<script>
    $(function() {
        function test() {
            $(".test_obj > div ").each(function (i) {
                var $this  = $(this),
                    location = $this.data('width');
                $this.css({'width' : location + '%'});
            });
        }
        if($().appear) {
            $('.test_obj').appear().on('appear'function() {
                test();
            });
        } else {
            test();
        }
    });
</script>
구현 예시
반응형