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
Copy file name to clipboardExpand all lines: README.md
+3-32Lines changed: 3 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -78,7 +78,7 @@ You can pass options and callbacks into Smooth Scroll through the `init()` funct
78
78
79
79
```javascript
80
80
smoothScroll.init({
81
-
selector:'[data-scroll]', // Selector for links (must be a valid CSS selector)
81
+
selector:'[data-scroll]', // Selector for links (must be a class, ID, data attribute, or element tag)
82
82
selectorHeader:'[data-scroll-header]', // Selector for fixed headers (must be a valid CSS selector)
83
83
speed:500, // Integer. How fast to complete the scroll in milliseconds
84
84
easing:'easeInOutCubic', // Easing pattern to use
@@ -88,6 +88,8 @@ smoothScroll.init({
88
88
});
89
89
```
90
90
91
+
***Note:****To programatically add Smooth Scroll to all anchor links on a page, pass `selector: 'a'` into `init`. The script checks that the link points to the current page before running.*
92
+
91
93
#### Easing Options
92
94
93
95
**Linear**
@@ -248,37 +250,6 @@ Animated scrolling links at the very bottom of the page (example: a "scroll to t
248
250
249
251
250
252
251
-
## Programatically adding `[data-scroll]` attributes to all anchor links
252
-
253
-
Useful if you have anchor links scattered throughout a page, or if you're using WordPress's `wp_nav_menu()` function. Add this code to your JavaScript:
254
-
255
-
```js
256
-
;(function (window, document, undefined) {
257
-
258
-
'use strict';
259
-
260
-
// Cut the mustard
261
-
var supports = 'querySelector' in document && 'addEventListener' in window;
262
-
if ( !supports ) return;
263
-
264
-
// Get all anchors
265
-
var anchors = document.querySelectorAll( '[href*="#"]' );
266
-
267
-
// Add smooth scroll to all anchors
268
-
for ( var i = 0, len = anchors.length; i < len; i++ ) {
269
-
var url = new RegExp( window.location.hostname + window.location.pathname );
270
-
if ( !url.test( anchors[i].href ) ) continue;
271
-
anchors[i].setAttribute( 'data-scroll', true );
272
-
}
273
-
274
-
// Initial smooth scroll (add your attributes as desired)
275
-
smoothScroll.init();
276
-
277
-
})(window, document);
278
-
```
279
-
280
-
281
-
282
253
## How to Contribute
283
254
284
255
Please review the [contributing guidelines](CONTRIBUTING.md).
0 commit comments