-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.html
141 lines (134 loc) · 3.11 KB
/
example.html
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>prevent background scroll</title>
<style>
.box {
height: 150px;
background-color: aliceblue;
}
.bg-red {
background-color: darkred;
}
.bg-blue {
background-color: deepskyblue;
}
.bg-green {
background-color: aquamarine;
}
.bg-dark {
background-color: darkslategray;
}
.modal {
position: fixed;
top: 0;
left: 0;
height: 100vh;
width: 100vw;
background-color: rgba(0, 0, 0, 0.5);
display: none;
}
.modal.show {
display: block;
}
.modal__content {
width: 100%;
height: 420px;
background-color: #FFF;
position: absolute;
bottom: 0;
}
.modal__head {
height: 32px;
line-height: 32px;
border-bottom: 1px solid #ccc;
}
.modal__body {
height: calc(320px - 33px);
overflow: scroll;
-webkit-overflow-scrolling: touch;
}
.modal__close {
float: right;
}
</style>
</head>
<body>
<div class="box"></div>
<div class="box bg-red"></div>
<div class="box bg-green"></div>
<div class="box bg-blue"></div>
<div class="box bg-green"></div>
<div class="box bg-red"></div>
<div class="box bg-blue"></div>
<div class="box bg-dark"></div>
<div class="box bg-red"></div>
<div class="box bg-dark"></div>
<button type="button" class="btn">show modal</button>
<button type="button" class="btn1">destroy</button>
<div class="modal">
<div class="modal__content">
<div class="modal__head">
modal title
<span class="modal__close">close</span>
</div>
<div class="modal__body" data-scroll-container>
<ul>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>8</li>
<li>7</li>
<li>6</li>
<li>5</li>
<li>4</li>
<li>3</li>
<li>2</li>
<li>1</li>
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>8</li>
<li>7</li>
<li>6</li>
<li>5</li>
<li>4</li>
<li>3</li>
<li>2</li>
<li>1</li>
</ul>
</div>
</div>
</div>
<script type="module">
import LockBgScroll from './LockBgScroll.mjs'
var btn = document.querySelector('button.btn')
var btn1 = document.querySelector('button.btn1')
var modal = document.querySelector('.modal')
var close = document.querySelector('.modal__close')
btn.addEventListener('click', () => {
modal.classList.add('show')
})
close.addEventListener('click', () => {
modal.classList.remove('show')
})
let lbs = new LockBgScroll(modal).init()
btn1.addEventListener('click', () => {
lbs.destroy()
})
</script>
</body>
</html>