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
*__Quick aside:__ you might not need this library. There's [a native CSS way to handle smooth scrolling](https://gomakethings.com/smooth-scrolling-links-with-only-css/) that might fit your needs.*
5
9
6
10
7
11
<hr>
@@ -39,13 +43,21 @@ You can also use the [jsDelivr CDN](https://cdn.jsdelivr.net/gh/cferdinandi/smoo
You can also use NPM (or your favorite package manager).
58
+
59
+
```bash
60
+
npm install smooth-scroll
49
61
```
50
62
51
63
### 2. Add the markup to your HTML.
@@ -153,13 +165,13 @@ var scroll = new SmoothScroll('a[href*="#"]', {
153
165
154
166
155
167
156
-
## Options and Settings
168
+
## API
157
169
158
170
Smooth Scroll includes smart defaults and works right out of the box. But if you want to customize things, it also has a robust API that provides multiple ways for you to adjust the default options and settings.
159
171
160
-
### Global Settings
172
+
### Options and Settings
161
173
162
-
You can pass options and callbacks into Smooth Scroll through the `init()` function:
174
+
You can pass options and callbacks into Smooth Scroll when instantiating.
You can also call Smooth Scroll's methods in your own scripts.
261
+
Smooth Scroll also exposes several public methods.
250
262
251
263
#### animateScroll()
252
264
Animate scrolling to an anchor.
@@ -296,16 +308,8 @@ scroll.cancelScroll();
296
308
297
309
***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.*
298
310
299
-
#### init()
300
-
Initialize Smooth Scroll. This is called automatically when you setup your `new SmoothScroll` object, but can be used to reinitialize your instance.
301
-
302
-
```javascript
303
-
var scroll =newSmoothScroll();
304
-
scroll.init('.some-selector');
305
-
```
306
-
307
311
#### destroy()
308
-
Destroy the current `smoothScroll.init()`. This is called automatically during the `init`function to remove any existing initializations.
312
+
Destroy the current initialization. This is called automatically in the `init`method to remove any existing initializations.
309
313
310
314
```javascript
311
315
var scroll =newSmoothScroll();
@@ -333,34 +337,21 @@ If you have multiple fixed headers, pass in the last one in the markup.
333
337
334
338
335
339
336
-
## Working with the Source Files
337
-
338
-
If you would prefer, you can work with the development code in the `src` directory using the included [Gulp build system](http://gulpjs.com/). This compiles, lints, and minifies code.
1. In bash/terminal/command line, `cd` into your project directory.
349
-
2. Run `npm install` to install required files.
350
-
3. When it's done installing, run one of the task runners to get going:
351
-
* `gulp` manually compiles files.
352
-
* `gulp watch` automatically compiles files when changes are made and applies changes using [LiveReload](http://livereload.com/).
340
+
## What's new?
353
341
342
+
Scroll duration now varies based on distance traveled. If you want to maintain the old scroll animation duration behavior, set the `speedAsDuration` option to `true`.
354
343
355
344
356
345
357
-
## Migrating to Smooth Scroll 15 from Older Versions
346
+
## Known Issues
358
347
359
-
Scroll duration now varies based on distance traveled. If you want to maintain the old scroll animation duration behavior, set the `speedAsDuration` option to `true`.
348
+
### Reduce Motion Settings
360
349
350
+
This isn't really an "issue" so-much as a question I get a lot.
361
351
352
+
Smooth Scroll respects [the `Reduce Motion` setting](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion) available in certain operating systems. In browsers that surface that setting, Smooth Scroll will not run and will revert to the default "jump to location" anchor link behavior.
362
353
363
-
## Known Issues
354
+
I've decided to respect user preferences of developer desires here. This is *not* a configurable setting.
364
355
365
356
### `<body>` styling
366
357
@@ -384,6 +375,8 @@ Smooth Scroll works in all modern browsers, and IE 9 and above.
384
375
385
376
Smooth Scroll is built with modern JavaScript APIs, and uses progressive enhancement. If the JavaScript file fails to load, or if your site is viewed on older and less capable browsers, anchor links will jump the way they normally would.
386
377
378
+
*__Note:__ Smooth Scroll will not run—even in supported browsers—if users have `Reduce Motion` enabled. [Learn more in the "Known Issues" section.](#reduce-motion-settings)*
379
+
387
380
### Polyfills
388
381
389
382
Support back to IE9 requires polyfills for `closest()`, `requestAnimationFrame()`, and `CustomEvent()`. Without them, support starts with Edge.
0 commit comments