Skip to content

Commit 3e9d4a9

Browse files
committed
Updated readme
1 parent aaa1307 commit 3e9d4a9

File tree

1 file changed

+14
-5
lines changed

1 file changed

+14
-5
lines changed

README.md

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ scroll.animateScroll( anchor, toggle, options );
184184

185185
```javascript
186186
// You can optionally pass in a y-position to scroll to as an integer
187-
smoothScroll.animateScroll( 750 );
187+
var scroll = new SmoothScroll();
188+
scroll.animateScroll( 750 );
188189
```
189190

190191
#### cancelScroll()
@@ -197,6 +198,14 @@ scroll.cancelScroll();
197198

198199
***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.*
199200

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 = new SmoothScroll();
206+
scroll.init('.some-selector');
207+
```
208+
200209
#### destroy()
201210
Destroy the current `smoothScroll.init()`. This is called automatically during the `init` function to remove any existing initializations.
202211

@@ -218,8 +227,8 @@ If you have multiple fixed headers, pass in the last one in the markup.
218227
</nav>
219228
...
220229
<script>
221-
smoothScroll.init({
222-
selectorHeader: '[data-scroll-header]'
230+
var scroll = new SmoothScroll('.some-selector',{
231+
header: '[data-scroll-header]'
223232
});
224233
</script>
225234
```
@@ -297,7 +306,7 @@ Frequently asked questions, code snippets, and more to help you get the most out
297306

298307
This, unfortunately, cannot be done well.
299308

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.
301310

302311
### Scrolling without updating the URL
303312

@@ -307,7 +316,7 @@ A benefit of this approach is that it preserves browser history and let's users
307316

308317
*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.
309318

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()`.
311320

312321
```js
313322
var scroll = new SmoothScroll();

0 commit comments

Comments
 (0)