-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.html
324 lines (249 loc) · 11.4 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
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
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
<!Doctype html>
<html>
<head>
<meta charset="utf-8">
<title>jQuery UI Scrollable Widget</title>
<script src="http://code.jquery.com/jquery.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script src="jquery-ui-scrollable.js"></script>
<style>
body {
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
}
pre {
background-color: #F8F8F8;
border: 1px solid #DDDDDD;
border-radius: 3px 3px 3px 3px;
font-size: 13px;
line-height: 19px;
overflow: auto;
padding: 6px 10px;
}
code {
white-space: nowrap;
background-color: #F8F8F8;
border: 1px solid #DDDDDD;
border-radius: 3px 3px 3px 3px;
margin: 0 2px;
padding: 0 5px;
}
pre > code {
background-color: transparent;
border: medium none;
margin: 0;
padding: 0;
white-space: pre;
}
.nav-bar {
border-right: 1px solid #efefef;
position: fixed;
top: 0;
left: 0;
bottom: 0;
width: 300px;
padding-top: 58px;
}
.nav-bar h3 {
cursor: pointer;
padding: 5px 25px 5px;
text-align: right;
}
.nav-bar .selected {
background-color: #d6ebff;
}
.content {
margin-left: 300px;
}
.content h1 {
margin-left: -8px;
margin-right: -8px;
padding: 10px;
background-color: #efefef;
}
.content div.section {
margin-bottom: 80px;
}
.title {
position: fixed;
text-align: right;
top: 300px;
left: 100px;
}
</style>
</head>
<body>
<a href="https://github.com/bseth99/jquery-ui-scrollable"><img style="position: fixed; top: 0; left: 0; border: 0; z-index: 1" src="https://s3.amazonaws.com/github/ribbons/forkme_left_red_aa0000.png" alt="Fork me on GitHub"></a>
<h1 class="title">jQuery<br/> UI<br/> Scrollable</h1>
<div class="nav-bar">
</div>
<div class="content">
<h1>Overview</h1>
<div class="section">
A jQuery UI widget that enables monitoring, querying, or changing the scroll position of an element relative to
a scrolling container. Read about the journey to get here on
my blog post - <a href="http://www.benknowscode.com/2013/07/detect-dom-element-scrolled-with-jquery.html">
benknowscode.com/2013/07/detect-dom-element-scrolled-with-jquery</a>
<h2>Features</h2>
<ul>
<li><b>Detect</b>: Monitors whether target elements scroll in/out of the visible view of a scroll container (not just the window).
Allows configuring a logical size of the container to affect where the target must actually be located before triggering events.</li>
<li><b>Query</b>: Provides location information identifying where the target element is located relative to the container (top, left, bottom, right).</li>
<li><b>Change</b>: Enables animated scrolling of the target into the container with any of the built-in jQuery easing options and flexible
positioning settings.</li>
</ul>
<h2>Download</h2>
<div>
Either download the
<a href="https://raw.github.com/bseth99/jquery-ui-scrollable/master/jquery-ui-scrollable.min.js">Minified</a> or the
<a href="https://raw.github.com/bseth99/jquery-ui-scrollable/master/jquery-ui-scrollable.js">Full</a> source and add it
after the normal jQuery UI scripts.
</div>
</div>
<h1>Usage</h1>
<div class="section">
<p>A scrolling element is either the window or an element with the <code>overflow</code> style set to
<code>auto</code> or <code>scroll</code></p>
<pre><code> $('#myelement').scrollable()
</code></pre>
<p>This will add myelement to the list of elements being monitored for their scroll position. If the element scrolls into
the visible viewport defined by its container, then an <code>in</code> event is triggered. When it scrolls out, an
<code>out</code> event is triggered. Each event is triggered only one time when an element moves in and out of view.</p>
<h3>
<a href="#options" class="anchor" name="options"><span class="octicon octicon-link"></span></a>Options</h3>
<p><code>direction</code> - Determines if monitoring/positioning will occur for either <code>both</code>, <code>vertical</code> only, or
<code>horizontal</code> only. Defaults to <code>both</code>. </p>
<pre><code> $('#myelement').scrollable({ direction: 'vertical' });
</code></pre>
<p><code>offset</code> - Adjust the logical size of the container such that the detection compares to a different
sized box than the physical one displayed in the browser. Accepts pixels and percentages. Accepts <code>left</code>,
<code>top</code>, <code>right</code>, and <code>bottom</code> to set each side individually or <code>vertical</code>/<code>y</code> and
<code>horizonal</code>/<code>x</code> which will split the value evenly between the top/bottom and left/right, respectively.
Any missing values will default to zero. Positive value shrink the box while negative expand it.</p>
<pre><code> // Adjust the bounds of the top/left side of the detection zone
$('#myelement').scrollable({ offset: { left: '40%', top: '40%' } });
// Adjust the bounds of the left/right only (20% for each) and leave top/bottom alone
$('#myelement').scrollable({ offset: { x: '40%' } });
</code></pre>
<p>See the <a href="http://bseth99.github.io/jquery-ui-scrollable/examples/offset.html">example</a> to see how it works. </p>
<h3>
<a href="#methods" class="anchor" name="methods"><span class="octicon octicon-link"></span></a>Methods</h3>
<p><code>position</code> - returns an object hash describing the state of the element relative to the scrolling container's
visible viewport:</p>
<ul>
<li>
<code>container</code> [Object] - The normalized (after applying <code>offset</code>) left/right/top/bottom points of
the container element.</li>
<li>
<code>element</code> [Object] - The left/right/top/bottom points of the target element.</li>
<li>
<code>inside</code> [Boolean] - Is the element inside the defined visible viewport.</li>
<li>
<code>outside</code> [Boolean] - Is the element outside the defined visible viewport.</li>
<li>
<code>left</code> [Boolean] - Is the element left of the defined visible viewport.</li>
<li>
<code>right</code> [Boolean] - Is the element right of the defined visible viewport.</li>
<li>
<code>top</code> [Boolean] - Is the element above the defined visible viewport.</li>
<li>
<code>bottom</code> [Boolean] - Is the element below the defined visible viewport.</li>
</ul><p><code>goto</code> - Scrolls the element into the visible viewport. Uses jQuery.animate to smooth the transistion.
Takes an optional config object with the following options:</p>
<ul>
<li>
<code>onlyOutside</code> - Should the element be scrolled if its already in the visible area.</li>
<li>
<code>my</code> - Determines the final positioning of the target element relative to the container.</li>
<li>
<code>at</code> - Determines where the element should be positioned relative to the container.<br>
See the documentation on <a href="http://api.jqueryui.com/position/">jQuery UI Position</a> for the format of <code>my</code> and <code>at</code>.</li>
<li>
<code>duration</code> - Same options as <a href="http://api.jquery.com/animate/">jQuery.animate()</a>
</li>
<li>
<code>easing</code> - Accepts all the easing options available in <a href="http://jqueryui.com/effect/#easing">jQuery UI</a>
</li>
<li>
<code>complete</code> - callback function to execute once animation completes</li>
</ul><p>See the <a href="http://bseth99.github.io/jquery-ui-scrollable/examples/goto.html">example</a> to experiment
with the positioning options.</p>
<h3>
<a href="#events" class="anchor" name="events"><span class="octicon octicon-link"></span></a>Events</h3>
<p><code>in</code> - triggered when the element scrolls into the defined viewport.</p>
<pre><code> $('#myelement').scrollable({
in: function ( e, ui ) {
...
}
});
</code></pre>
<p>or </p>
<pre><code> $('#myelement').on('scrollin', function ( e, ui ) {
...
});
</code></pre>
<p><code>e</code> is the original scroll event.</p>
<p>The <code>ui</code> object contains the following keys:</p>
<ul>
<li>
<code>container</code> [jQuery] - The closest scrolling ancestor container of the target element</li>
<li>
<code>element</code> [jQuery] - The target element</li>
<li>
<code>position</code> [Object] - The same object hash that is returned by the <code>position</code> method.</li>
</ul><p><code>out</code> - triggered when the element scrolls out of the defined viewport. Same parameters and usage as <code>in</code>.</p>
</div>
<h1>Demos</h1>
<div class="section">
This page serves as one of the demos. The navigation bar on the left will track along as you scroll
down this page. Each topic has a header which are being tracked by Scrollable. As they enter the bottom of the
window, the <code>in</code> event fires which handles updating the navigation bar. Click each section on the
navigation menu on the left will animate the section into view using the <code>goto</code> method.
<ul>
<li><a href="examples/event.html">Event with Multiple Containers</a></li>
<li><a href="examples/goto.html">Animated Scroll with Goto Method</a></li>
<li><a href="examples/offset.html">Adjust Viewport Size with Offset</a></li>
<li><a href="examples/slideshow.html">Create a Simple Image Slideshow</a></li>
<li><a href="examples/dynamic-menu.html">Dynamically Collaping Menu</a></li>
</ul>
</div>
</div>
<script>
$(function() {
var $nav = $( '.nav-bar' ),
$ps = $( '.content > .section' ),
$hs = $( '.content > h1' );
$.osb.scrollable.CONFIG.throttler = 0;
$(window).on('resize', function() {
var wh = $(window).height();
$hs.each( function(i) {
var $pi = $ps.eq( i ),
ph = $pi.height();
if ( ph < wh )
$pi.css( 'margin-bottom', wh - ph );
});
}).trigger('resize');
$hs.each( function(i) {
$('<h3>')
.text( $(this).text() )
.appendTo( $nav )
.click( function() {
$hs.eq( $(this).index() ).scrollable( 'goto', {
my: 'top',
at: 'top'
} );
});
})
.scrollable({
direction: 'vertical',
offset: { bottom: '50%' },
in: function ( e, ui ) {
$nav.children()
.removeClass( 'selected' )
.eq( ui.element.index( '.content > h1' ) )
.addClass( 'selected' );
}
});
});
</script>
</body>
</html>