Skip to content

Commit fb8eadf

Browse files
author
cferdinandi
committed
Updated readme
1 parent adf5498 commit fb8eadf

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

README.md

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,22 +233,24 @@ Useful if you have anchor links scattered throughout a page, or if you're using
233233
```js
234234
;(function (window, document, undefined) {
235235

236-
'use strict';
236+
'use strict';
237237

238-
// Cut the mustard
238+
// Cut the mustard
239239
var supports = 'querySelector' in document && 'addEventListener' in window;
240-
if ( !supports ) return;
240+
if ( !supports ) return;
241241

242-
// Get all anchors
243-
var anchors = document.querySelectorAll( '[href*="#"]' );
242+
// Get all anchors
243+
var anchors = document.querySelectorAll( '[href*="#"]' );
244244

245245
// Add smooth scroll to all anchors
246246
for ( var i = 0, len = anchors.length; i < len; i++ ) {
247+
var url = new RegExp( window.location.hostname + window.location.pathname );
248+
if ( !url.test( anchors[i].href ) ) continue;
247249
anchors[i].setAttribute( 'data-scroll', true );
248250
}
249251

250252
// Initial smooth scroll (add your attributes as desired)
251-
smoothScroll.init();
253+
smoothScroll.init();
252254

253255
})(window, document);
254256
```

0 commit comments

Comments
 (0)