Skip to content

Commit f0f84a1

Browse files
authored
Updated readme (cferdinandi#269)
1 parent 8c33886 commit f0f84a1

File tree

1 file changed

+3
-32
lines changed

1 file changed

+3
-32
lines changed

README.md

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ You can pass options and callbacks into Smooth Scroll through the `init()` funct
7878

7979
```javascript
8080
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)
8282
selectorHeader: '[data-scroll-header]', // Selector for fixed headers (must be a valid CSS selector)
8383
speed: 500, // Integer. How fast to complete the scroll in milliseconds
8484
easing: 'easeInOutCubic', // Easing pattern to use
@@ -88,6 +88,8 @@ smoothScroll.init({
8888
});
8989
```
9090

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+
9193
#### Easing Options
9294

9395
**Linear**
@@ -248,37 +250,6 @@ Animated scrolling links at the very bottom of the page (example: a "scroll to t
248250

249251

250252

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-
282253
## How to Contribute
283254

284255
Please review the [contributing guidelines](CONTRIBUTING.md).

0 commit comments

Comments
 (0)