-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
scrollspy.html
180 lines (170 loc) · 5.82 KB
/
scrollspy.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
<!DOCTYPE html>
<html lang="en">
<head>
{{> head }}
</head>
<body>
{{> navbar }}
<main>
{{> intro}}
<div class="container">
<div class="row">
<div class="col s12 m8 offset-m1 xl7 offset-xl1">
<div id="introduction" class="section scrollspy">
<p class="caption">
Scrollspy tracks certain elements and which element the user's screen is currently centered on. Our main demo of this is our table of contents on every
documentation page to the right. Clicking on these links will also scroll the page to that element.
</p>
<pre><code class="language-html">
<xmp>
<div class="row">
<div class="col s12 m9 l10">
<div id="introduction" class="section scrollspy">
<p>Content</p>
</div>
<div id="structure" class="section scrollspy">
<p>Content</p>
</div>
<div id="initialization" class="section scrollspy">
<p>Content</p>
</div>
</div>
<div class="col hide-on-small-only m3 l2">
<ul class="section table-of-contents">
<li><a href="#introduction">Introduction</a></li>
<li><a href="#structure">Structure</a></li>
<li><a href="#initialization">Initialization</a></li>
</ul>
</div>
</div>
</xmp>
</code></pre>
</div>
<div id="initialization" class="scrollspy section">
<h3 class="header">Initialization</h3>
<pre><code class="language-javascript">
document.addEventListener('DOMContentLoaded', function() {
var elems = document.querySelectorAll('.scrollspy');
var instances = M.ScrollSpy.init(elems, {
// specify options here
});
});
</code></pre>
</div>
<div id="options" class="scrollspy section">
<h3 class="header">Options</h3>
<table class="striped">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Default</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>throttle</td>
<td>Number</td>
<td>100</td>
<td>Throttle of scroll handler.</td>
</tr>
<tr>
<td>scrollOffset</td>
<td>Number</td>
<td>200</td>
<td>Offset for centering element when scrolled to.</td>
</tr>
<tr>
<td>activeClass</td>
<td>String</td>
<td>'active'</td>
<td>Class applied to active elements.</td>
</tr>
<tr>
<td>getActiveElement</td>
<td>Function</td>
<td></td>
<td>Used to find active element.</td>
</tr>
</tbody>
</table>
<h5>getActiveElement</h5>
This is the default function used for finding the active element where id is the id of the scrollspy element. It returns a CSS selector of the element you want marked
active.
<pre><code class="language-javascript">
function(id) {
return 'a[href="#' + id + '"]';
}
</code></pre>
</div>
<div id="methods" class="scrollspy section">
<h3 class="header">Methods</h3>
<blockquote>
<p>All the methods are called on the plugin instance. You can get the plugin instance like this:</p>
<pre><code class="language-javascript col s12">
var instance = M.ScrollSpy.getInstance(elem);
</code></pre>
</blockquote>
<h5 class="method-header">.destroy();</h5>
<p>Destroy plugin instance and teardown</p>
<pre><code class="language-javascript col s12">
instance.destroy();
</code></pre>
</div>
<div id="properties" class="scrollspy section">
<h3 class="header">Properties</h3>
<table class="striped">
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>el</td>
<td>Element</td>
<td>The DOM element the plugin was initialized with.</td>
</tr>
<tr>
<td>options</td>
<td>Object</td>
<td>The options the instance was initialized with.</td>
</tr>
</tbody>
</table>
</div>
</div>
<!-- Table of Contents -->
<div class="col hide-on-small-only m3 xl3">
<div class="toc-wrapper">
<div style="height: 1px">
<ul class="section table-of-contents">
<li>
<a href="#introduction">Introduction</a>
</li>
<li>
<a href="#initialization">Initialization</a>
</li>
<li>
<a href="#options">Options</a>
</li>
<li>
<a href="#methods">Methods</a>
</li>
<li>
<a href="#properties">Properties</a>
</li>
</ul>
</div>
</div>
</div>
</div>
</div>
</main>
{{> footer }}
<script type="module" src="/src/main.ts"></script>
</body>
</html>