-
Notifications
You must be signed in to change notification settings - Fork 1
/
demo.html
216 lines (184 loc) · 7.22 KB
/
demo.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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
<!DOCTYPE html>
<html>
<head>
<style>
body {
margin: 0;
}
#container {
display: flex;
align-items: center;
flex-direction: column;
font-family: 'Lucida Sans', 'Lucida Sans Regular', 'Lucida Grande', 'Lucida Sans Unicode', Geneva, Verdana, sans-serif;
width: 100%;
height: 100%;
}
#container > * {
flex: 0 0 auto;
}
#container .scrollbar::after {
position: absolute;
background-color: grey;
content: " ";
}
#container .expanded.scrollbar::after, #container .scrollbar:hover::after {
transition: linear 100ms;
width: 10;
left: -10px;
}
#container .scrollbar::after {
transition: linear 500ms;
width: 4px;
height: 100%;
left: -4px;
}
#simple-example {
height: 700px;
width: 80%;
position: relative;
}
#simple-example-inner {
position: absolute;
top: 50px;
left: 250px;
height: 200px;
width: 300px;
border: 1px solid black;
}
#simple-example .scrollbar::after {
position: absolute;
background-color: white;
content: " ";
border-radius: 3px;
opacity: 0.75;
}
#simple-example .scrollbar.vertical::after {
width: 6px;
height: calc(100% - 8px);
left: -10px;
margin: 4px 0;
}
#simple-example .scrollbar.horizontal::after {
height: 6px;
width: calc(100% - 8px);
top: -10px;
margin: 0 4px;
}
#advanced-example {
height: 700px;
width: 80%;
}
#advanced-example .scrollbar::after {
position: absolute;
background-color: black;
content: " ";
border-radius: 3px;
opacity: 0;
transition: opacity linear 500ms;
}
#advanced-example .visible.scrollbar::after, #advanced-example .scrollbar:hover::after {
transition: opacity linear 50ms;
opacity: 1;
}
#advanced-example .scrollbar.vertical::after {
width: 6px;
height: calc(100% - 8px);
left: -10px;
margin: 4px 0;
}
#advanced-example .scrollbar.horizontal::after {
height: 6px;
width: calc(100% - 8px);
top: -10px;
margin: 0 4px;
}
.spacer {
height: 50px;
width: 100%;
}
</style>
</head>
<body>
<div id="container">
<h1>Simple example</h1>
<div class="description">
This is a simple example with a normal scroll area. Additionally, there is a another scrollarea
inside the main scrollarea, to check out that behaviour.
</div>
<div id="simple-example">
<div>
<img src="https://upload.wikimedia.org/wikipedia/commons/f/f7/DSC0210-w-busch-realschule-neuperlach-alpenkulisse.jpg" />
</div>
<div id="simple-example-inner">
<img src="https://upload.wikimedia.org/wikipedia/commons/2/27/Mars_transparent.png" />
</div>
</div>
<div class="spacer"></div>
<h1>Advanced example</h1>
<div class="description">
This is a little more advanced example, showing animated scrollbars, that fade in when the user
scrolls, and fade out when the user stops scrolling.
</div>
<div id="advanced-example">
<img src="https://upload.wikimedia.org/wikipedia/commons/1/17/Church_in_Flowers.jpg" />
</div>
<div class="spacer"></div>
<div id="credits">
<div>
This demo belongs to the <a href="https://github.com/sateffen/poc-scrollbar/">PocScrollbar</a>.
</div>
<div>
All used images are provided by <a href="https://commons.wikimedia.org/wiki/Main_Page" alt="Wikimedia Mainpage">Wikimedia</a>.
They are chosen randomly. All credits belong to the original owners.
</div>
<ul>
<li><a href="https://commons.wikimedia.org/wiki/File:Mars_transparent.png">https://commons.wikimedia.org/wiki/File:Mars_transparent.png</a></li>
<li><a href="https://commons.wikimedia.org/wiki/File:DSC0210-w-busch-realschule-neuperlach-alpenkulisse.jpg">https://commons.wikimedia.org/wiki/File:DSC0210-w-busch-realschule-neuperlach-alpenkulisse.jpg</a></li>
<li><a href="https://commons.wikimedia.org/wiki/File:Church_in_Flowers.jpg">https://commons.wikimedia.org/wiki/File:Church_in_Flowers.jpg</a></li>
</ul>
</div>
</div>
<script src="dist/pocscrollbar.js"></script>
<script>
var container = document.querySelector('#container');
var simpleExample = document.querySelector('#simple-example');
var simpleExampleInner = document.querySelector('#simple-example-inner');
var advancedExample = document.querySelector('#advanced-example');
var containerScrollbar = new window.PocScrollbar(container, {
disableXScrolling: true,
yElementClass: ['scrollbar', 'vertical']
});
var containerTimer = null;
function animateContainer(aEvent) {
var target = aEvent.target;
target.classList.add('expanded');
window.clearTimeout(containerTimer);
containerTimer = window.setTimeout(function () {target.classList.remove('expanded');}, 300);
}
containerScrollbar.addEventListener('scrollTopChanged', animateContainer);
var simpleExampleScrollbar = new window.PocScrollbar(simpleExample, {
xElementClass: ['scrollbar', 'horizontal'],
yElementClass: ['scrollbar', 'vertical']
});
var simpleExampleInnerScrollbar = new window.PocScrollbar(simpleExampleInner, {
xElementClass: ['scrollbar', 'horizontal'],
yElementClass: ['scrollbar', 'vertical'],
yOverscrollBehaviour: 'none'
});
var advancedExampleScrollbar = window.scrollerInnerInstance = new window.PocScrollbar(advancedExample, {
xElementClass: ['scrollbar', 'horizontal'],
yElementClass: ['scrollbar', 'vertical']
});
var advancedExampleTimer = {x: null, y: null};
function animateAdvancedExample(aEvent) {
var direction = aEvent.type === 'scrollTopChanged' ? 'y' : 'x';
var target = aEvent.target;
target.classList.add('visible');
window.clearTimeout(advancedExampleTimer[direction]);
advancedExampleTimer[direction] = window.setTimeout(function () {target.classList.remove('visible');}, 750);
}
advancedExampleScrollbar.addEventListener('scrollTopChanged', animateAdvancedExample);
advancedExampleScrollbar.addEventListener('scrollLeftChanged', animateAdvancedExample);
</script>
</body>
</html>