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
2020. 3. 21. 22:49

반응형
jQuery
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<script>
    // 스크롤 제한 ON
    function scroll_on() {
        $('(적용대상)').on('scroll touchmove mousewheel'function(e) {
            e.preventDefault();
            e.stopPropagation();
            return false;
        });
    }
  
    // 스크롤 제한 OFF
    function scroll_off() {
        $('(적용대상)').off('scroll touchmove mousewheel');
    }
</script>
예제 소스
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
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
  
<style>
    body {
        margin: 0;
        padding: 0;
        background: linear-gradient(#e66465, #9198e5);
        position: relative;
    }
  
    body div.container {
        width: 100%;
        height: 2500px;
    }
  
    body div.container div {
        position: absolute;
        width: 200px;
        height: 70px;
        line-height: 70px;
        text-align: center;
        font-size: 24px;
        top: 150px;
        background-color: #ffffff;
        border-radius: 15px;
        border: 1px solid rgba(0, 0, 0, 0.15);
        cursor: pointer;
    }
  
    body div:first-child {
        left: 20%;
    }
  
    body div:last-child {
        right: 20%;
    }  
</style>
  
<body>
<div class="container">
    <div onclick="scroll_on()">스크롤 제한 ON</div>
    <div onclick="scroll_off()">스크롤 제한 OFF</div>
</div>
</body>
  
<script>
    // 스크롤 제한 ON
    function scroll_on() {
        $('.container').on('scroll touchmove mousewheel'function(e) {
            e.preventDefault();
            e.stopPropagation();
            return false;
        });
    }
  
    // 스크롤 제한 OFF
    function scroll_off() {
        $('.container').off('scroll touchmove mousewheel');
    }
</script>
구현 예시
반응형