-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.html
267 lines (245 loc) · 13.2 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Untitled</title>
<!-- Include jQuery and the plugin -->
<script type="text/javascript" src="lib/jquery-2.1.4.min.js"></script>
<!--script type="text/javascript" src="js/min/jquery-scrollupdownevent-min.js"></script-->
<script type="text/javascript" src="js/jquery-advscrollevent.js"></script>
<script type="text/javascript">
function showPanels() {
$("#toppanel").css("top", "0");
$("#bottompanel").css("bottom", "0");
};
function hidePanels() {
var tp = $("#toppanel");
tp.css("top", "-" + (tp.outerHeight() + 10) + "px" ); //10 px shadow
$("#bottompanel").css("bottom", "-5em");
}
$(function() {
var commonSettings = {
upBy: 100,
downBy: 10,
downUpDelayMillis: 0
};
$(window).advScroll($.extend({}, commonSettings, {
onUp: function(evt, px) {
showPanels();
$("#diff .value").html("↑ " + px);
},
onTop: function(evt, px, top) {
showPanels();
$("#diff .value").html("⊤ " + px);
},
onDown: function(evt, px, top) {
hidePanels();
$("#diff .value").html("↓ " + px);
},
onBottom: function(evt, px, top) {
showPanels();
$("#diff .value").html("⊥ " + px);
},
oncePerDirection: true
})).advScroll($.extend({}, commonSettings, {
onUp: function(evt, px) { $("#diffContinuous .value").html("↑ " + px);},
onDown: function(evt, px) { $("#diffContinuous .value").html("↓ " + px);},
onTop: function(evt, px) { $("#diffContinuous .value").html("⊤ " + px);},
onBottom: function(evt, px) { $("#diffContinuous .value").html("⊥ " + px);},
oncePerDirection: false
}));
$(".tableHolder").advScroll({
horizontal: true,
onUp: function(evt, px) { $("#tableDiff").html("← " + px);},
onDown: function(evt, px) { $("#tableDiff").html("→ " + px);},
onTop: function(evt, px) { $("#tableDiff").html("⇤ " + px);},
onBottom: function(evt, px) { $("#tableDiff").html("⇥ " + px);},
scrollableContent: "table"
});
});
</script>
<style type="text/css">
body {margin: 5em 20%}
p {padding-bottom: 2.5em; }
.panel {
background-color: rgba(255, 255, 200, 0.8);
margin:0;
padding: 0.5em 1em;
transition: bottom 0.5s, top 0.5s;
}
#toppanel {
position: fixed;
top:0; left:0; right:0;
box-shadow: 0 5px 10px rgba(0,0,0,0.5);
}
#bottompanel {
position: fixed;
bottom:0; left:0; right:0;
box-shadow: 0 -5px 10px rgba(0,0,0,0.5);
}
.diff {
position: fixed;
bottom:2em;
margin: 1em;
padding: 0.5em;
border-radius: 0.2em;
font-weight: bold;
color: white;
}
#diff {
right: 0;
background-color: red;
}
#diffContinuous {
left: 0;
background-color: green;
}
.tableHolder {
width: 100%;
overflow-x: scroll;
}
table td {
border: 1px silver;
background: #eee;
margin: 0.2em;
padding: 2em;
white-space: nowrap;
}
</style>
</head>
<body>
<div id="diff" class="diff"><div class="label">oncePerDirection</div><div class="value">0</div></div>
<div id="diffContinuous" class="diff"><div class="label">continuous</div><div class="value">0</div></div>
<div id="toppanel" class="panel">
This panel might contain e.g. a menu, toolbar, or a TOC (table of contents). It appears when scrolling up (backwards) and
gets closed when scrolling down (forwards).
</div>
<div id="bottompanel" class="panel">
this might be a toolbar panel.
</div>
<h1>Demo Page</h1>
<p>This page demonstrates one use case for the advscrollevent jQuery plug-in and some of its options.</p>
<h2>Monitoring vertical scrolling of page</h2>
<p>In this demo, the plug-in gets called twice for <code>$(window)</code>, once with the option <code>oncePerDirection: false</code>
(“continouous mode”)
and once with <code>oncePerDirection: true</code>. The first class registers event handlers for <code>onUp</code>, <code>onDown</code>,
<code>onTop</code> and <code>onBottom</code> which merely update the green box in the bottom left corner.
The second one also registers handlers for these four events, which not only update the contents of the red box in the lower right corner,
but also hide or show the top and bottom panels: They are shown on the onUp, onTop and onBottom events, while they are hidden
by the onDown event handler.</p>
<p>Both calls share some common options:</p>
<pre><code class="language-javascript">
var commonSettings = {
upBy: 100,
downBy: 10,
downUpDelayMillis: 0
};
</code></pre>
<p>Other properties are kept on default values.</p>
<p>
You'll notice the different settings for scrolling up or down, if you pay attention: First of all, after the page stood still for some seconds,
you'll have to scroll up by at least 100 pixels in order to trigger an up event (in both cases, continous mode or oncePerDirection, only in the latter
case the last scroll movement before has to have been a downward movement), while it takes only 10 pixels scrolling downwards to trigger the down event.
This difference was chosen on purpose, regarding the panel use case: The panels should not be shown on some minimal scrolling upwards, but only after
a “major” movement, while a much smaller downwards movements should be sufficient to hide them again.
</p>
<p>
On the other hand, an other default feature has been disabled for the up movement by setting <code>downUpDelayMillis</code> to zero:
This enforces that any upwards movement of at least 100px (see <code>upBy</code>) is immediately recognized, even if the
user had been scrolling downwards for quite a bit and suddenly changed to scrolling back upwards again without any pause
between these movements.<br>
Compare this to a up-down-direction change with the property <code>upDownDelayMillis</code> set on its default value
of currently 50ms. This means that if you are scrolling downwards and suddenly, without a pause (stand-still) of at least 0.05 seconds,
scroll upwards again, this will not be treated as scrolling upwards, but the plug-in will still (in continuous mode)
trigger down events with decreasing amount of scrolled pixels – as long as the upwards movement does neither exceed the point
where the downwards scrolling started, nor exceed the amount of pixels defined in the <code>directionChangeThreshold</code>
property, currently defaulting to 500 pixels.
</p>
<p>
This default behaviour of ignoring smaller scroll movements in opposite directions if they seem to be part of
the same movement (without a considerable stand-still in between) was chosen with regard of the fact, that,
especially when using your finger on a touch screen or touch pad, you might easily trigger minimal unintended
scrolling movements alone when putting your finger on top of the touch surface or when removing it again.
If, in this demo page, you are scrolling upwards an on stopping that, accidentally scroll downwards again even for
more than the 10 pixels specified in the <code>downBy</code> property, this won't trigger a down event would hide
the panels—as long as there were less than 50ms stand-still between scrolling upwards and downwards and as long as
the downwards movement does not exceed 500 pixels ond does not scroll beyond the point the initials upwards movement started.
</p>
<p>
Feel free to make copies of this demo page and vary the different options!
</p>
<h2>Monitoring horizontal scrolling of tables</h2>
<p>
This page also contains a second demonstration: This shows how to apply the plug-in to
other scrollable content of the page instead of <code>$(window)</code> as well as
the <code>horizontal</code> option.
</p>
<p>
Since a table won't be scrollable itself, even with CSS property <code>overflow-x: scroll</code>,
the following two tables are each wrapped in a <code><div class="tableHolder"></code> element with said overflow property.
The plug-in gets called on <code>$(".tableHolder")</code> and thus gets applied on both table holders
separately with only one call.
</p>
<p>
Have a look at the source code of this demo page for details. Pleas notice the use of the
<code>scrollableContent: "table"</code> option, which is needed by the plugin for triggering the
<code>onBottom</code> correctly: The plug-in has to calculate the width of the content of the
scrollable element, in this case the width of the table inside the tableHolder.
Both tables in this demo have different widths in order to demonstrate that the content width
is calculated individually for each tableHolder.
</p>
<div class="tableHolder">
<table>
<tr>
<td>Column 1</td>
<td>Column 2</td>
<td>Column 3</td>
<td>Column 4</td>
<td>Column 5</td>
<td>Column 6</td>
<td>Column 7</td>
<td>Column 8</td>
<td>Column 9</td>
<td>Column 10</td>
</tr>
</table>
</div>
<div class="tableHolder">
<table>
<tr>
<td>Second 1</td>
<td>Second 2</td>
<td>Second 3</td>
<td>Second 4</td>
<td>Second 5</td>
<td>Second 6</td>
</tr>
</table>
</div>
<p>Scroll us horizontally!<br>
<span id="tableDiff"></span></p>
<h2>Some more content</h2>
<p>
No need to read any further from here ;-)
</p>
<p>
The following Lorem ipsum boilerplate text was simply inserted on order to have some more scrollable
content to play with.
<p>
Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
</p><p>
Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat.
</p><p>
Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat. Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis at vero eros et accumsan et iusto odio dignissim qui blandit praesent luptatum zzril delenit augue duis dolore te feugait nulla facilisi.
</p><p>
Nam liber tempor cum soluta nobis eleifend option congue nihil imperdiet doming id quod mazim placerat facer possim assum. Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat. Ut wisi enim ad minim veniam, quis nostrud exerci tation ullamcorper suscipit lobortis nisl ut aliquip ex ea commodo consequat.
</p><p>
Duis autem vel eum iriure dolor in hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis.
</p><p>
At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, At accusam aliquyam diam diam dolore dolores duo eirmod eos erat, et nonumy sed tempor et et invidunt justo labore Stet clita ea et gubergren, kasd magna no rebum. sanctus sea sed takimata ut vero voluptua. est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat.
</p><p>
Consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus.
</p>
</body>
</html>