-
Notifications
You must be signed in to change notification settings - Fork 32
/
index.html
200 lines (173 loc) · 5.1 KB
/
index.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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
<!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>tua-body-scroll-lock demo</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/github-fork-ribbon-css/0.2.2/gh-fork-ribbon.min.css" />
</head>
<body>
<a
class="github-fork-ribbon right-bottom fixed"
target="_blank"
href="https://github.com/tuax/tua-body-scroll-lock"
title="Fork me on GitHub"
data-ribbon="Fork me on GitHub"
>
Fork me on GitHub
</a>
<header>
<h1>tua-body-scroll-lock demo</h1>
<img src="https://img.shields.io/badge/dependencies-none-green.svg" alt="dependencies">
<a href="https://www.npmjs.com/package/tua-body-scroll-lock" target="_blank">
<img src="https://badgen.net/npm/dm/tua-body-scroll-lock" alt="Downloads per month">
<img src="https://img.shields.io/npm/v/tua-body-scroll-lock.svg" alt="Version">
<img src="https://img.shields.io/npm/v/tua-body-scroll-lock/next.svg" alt="Next Version">
<img src="https://img.shields.io/npm/l/tua-body-scroll-lock.svg" alt="License">
</a>
</header>
<section class="content">
<button id="btn">click me to <br />show dialog one</button>
<button id="clearBtn">click me to <br />clear all body locks</button>
<div id="modalOne" class="modal">
<h2>
dialog one
<button id="modalBtn">click me to show dialog two</button>
</h2>
<div id="targetOne" class="target"></div>
<div id="targetTwo" class="target"></div>
</div>
<div id="modalTwo" class="modal">
<h2>dialog two with scroll-x</h2>
<div id="targetThree" class="target">
<p>123456789101112131415161718192021222324252627282930</p>
</div>
</div>
<div id="list"></div>
</section>
<script src="./tua-bsl.umd.js"></script>
<script type="module">
import { lock, unlock } from './tua-bsl.mjs'
var $ = document.querySelector.bind(document)
var $modalOne = $('#modalOne')
var $modalTwo = $('#modalTwo')
var $targetOne = $('#targetOne')
var $targetTwo = $('#targetTwo')
var $targetThree = $('#targetThree')
// add content
var someText = ''
for (var i = 0; i < 50; i++) {
someText += `<p>${i} scroll me~</p>`
}
$('#list').innerHTML = someText
$targetOne.innerHTML = someText
$targetTwo.innerHTML = someText
$targetThree.innerHTML += someText
$('#btn').onclick = function () {
$modalOne.style.display = 'block'
lock([$targetOne, $targetTwo], { useGlobalLockState: true })
}
$('#modalBtn').onclick = function () {
$modalTwo.style.display = 'block'
lock($targetThree, { useGlobalLockState: true })
}
$modalOne.onclick = function (event) {
if (event.target.id === 'targetOne') return
if (event.target.id === 'modalBtn') return
$modalOne.style.display = 'none'
unlock([$targetOne, $targetTwo], { useGlobalLockState: true })
}
$modalTwo.onclick = function (event) {
if (event.target.id === 'targetThree') return
$modalTwo.style.display = 'none'
unlock($targetThree, { useGlobalLockState: true })
}
$('#clearBtn').addEventListener('click', () => {
window.bodyScrollLock.clearBodyLocks({ useGlobalLockState: true })
})
</script>
<style>
* {
margin: 0;
padding: 0;
user-select: none;
}
html,
body {
width: 100%;
text-align: center;
}
header {
position: fixed;
top: 0;
right: 0;
left: 0;
background: #fff;
}
.content {
padding-top: 70px;
}
#btn {
position: fixed;
top: 150px;
left: 20px;
}
#list {
margin: 0 20px;
}
#modalTwo > h2 {
margin-top: 50px;
}
button {
padding: 6px;
color: #fff;
border-radius: 5px;
background-color: blue;
}
.modal {
position: fixed;
top: 0;
right: 0;
bottom: 0;
left: 0;
display: none;
padding-top: 40px;
background-color: rgba(0, 0, 0, 0.5);
}
h2 {
width: 80%;
max-width: 300px;
margin: 0 auto;
color: #000;
background-color: #fff;
}
.target {
overflow: scroll;
-webkit-overflow-scrolling: touch;
width: 80%;
max-width: 300px;
height: 60%;
margin: 0 auto;
text-align: center;
color: #000;
background-color: #fff;
}
#targetOne {
height: 30%;
color: blue;
border-bottom: 1px dashed black;
}
#targetTwo {
height: 30%;
color: red;
}
#clearBtn {
position: fixed;
bottom: 150px;
left: 20px;
z-index: 1;
}
</style>
</body>
</html>