You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// You can optionally pass in a y-position to scroll to as an integer
187
-
smoothScroll.animateScroll( 750 );
187
+
var scroll =newSmoothScroll();
188
+
scroll.animateScroll( 750 );
188
189
```
189
190
190
191
#### cancelScroll()
@@ -197,6 +198,14 @@ scroll.cancelScroll();
197
198
198
199
***Note:****This does not handle focus management. The user will stop in place, and focus will remain on the anchor link that triggered the scroll.*
199
200
201
+
#### init()
202
+
Initialize Smooth Scroll. This is called automatically when you setup your `new SmoothScroll` object, but can be used to reinitialize your instance.
203
+
204
+
```javascript
205
+
var scroll =newSmoothScroll();
206
+
scroll.init('.some-selector');
207
+
```
208
+
200
209
#### destroy()
201
210
Destroy the current `smoothScroll.init()`. This is called automatically during the `init` function to remove any existing initializations.
202
211
@@ -218,8 +227,8 @@ If you have multiple fixed headers, pass in the last one in the markup.
218
227
</nav>
219
228
...
220
229
<script>
221
-
smoothScroll.init({
222
-
selectorHeader:'[data-scroll-header]'
230
+
var scroll =newSmoothScroll('.some-selector',{
231
+
header:'[data-scroll-header]'
223
232
});
224
233
</script>
225
234
```
@@ -297,7 +306,7 @@ Frequently asked questions, code snippets, and more to help you get the most out
297
306
298
307
This, unfortunately, cannot be done well.
299
308
300
-
Most browsers instantly jump you to the anchor location when you load a page. You could use `scrollTo(0, 0)` to pull users back up to the top, and then manually use the `smoothScroll.animateScroll()` method, but in my experience, it results in a visible jump on the page that's a worse experience than the default browser behavior.
309
+
Most browsers instantly jump you to the anchor location when you load a page. You could use `scrollTo(0, 0)` to pull users back up to the top, and then manually use the `animateScroll()` method, but in my experience, it results in a visible jump on the page that's a worse experience than the default browser behavior.
301
310
302
311
### Scrolling without updating the URL
303
312
@@ -307,7 +316,7 @@ A benefit of this approach is that it preserves browser history and let's users
307
316
308
317
*However*, I know certain front-end frameworks also use URL hashes for their own internal processes. While I view this as an anti-pattern, and won't bake hashless anchor links into Smooth Scroll's core, you can enable scrolling without updating the URL via the Smooth Scroll API.
309
318
310
-
Here's a relatively lightweight helper function that listens for click events and uses the `smoothScroll.animateScroll()` method to scroll to the anchor. If you use this, you **should not**need initialize Smooth Scroll with `smoothScroll.init()`.
319
+
Here's a relatively lightweight helper function that listens for click events and uses the `animateScroll()` method to scroll to the anchor. If you use this, you **should not**pass a selector into `new SmoothScroll()`.
0 commit comments