Skip to content

Commit 8c33886

Browse files
committed
v9.2.0
Checks that link points to current page before running smooth scroll animation.
1 parent 576c9b3 commit 8c33886

File tree

6 files changed

+27
-17
lines changed

6 files changed

+27
-17
lines changed

dist/js/smooth-scroll.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* smooth-scroll v9.1.4: Animate scrolling to anchor links
2+
* smooth-scroll v9.2.0: Animate scrolling to anchor links
33
* (c) 2016 Chris Ferdinandi
44
* MIT License
55
* http://github.com/cferdinandi/smooth-scroll
@@ -292,7 +292,7 @@
292292
location = Math.max(location - headerHeight - offset, 0);
293293
return Math.min(location, getDocumentHeight() - getViewportHeight());
294294
};
295-
295+
296296
/**
297297
* Determine the viewport's height
298298
* @private
@@ -437,9 +437,14 @@
437437
// If a smooth scroll link, animate it
438438
var toggle = getClosest( event.target, settings.selector );
439439
if ( toggle && toggle.tagName.toLowerCase() === 'a' ) {
440+
441+
// Check that link is an anchor and points to current page
442+
if ( toggle.origin !== location.origin || toggle.pathname !== location.pathname ) return;
443+
440444
event.preventDefault(); // Prevent default click event
441445
var hash = smoothScroll.escapeCharacters( toggle.hash ); // Escape hash characters
442446
smoothScroll.animateScroll( hash, toggle, settings); // Animate scroll
447+
443448
}
444449

445450
};
@@ -511,4 +516,4 @@
511516

512517
return smoothScroll;
513518

514-
});
519+
});

dist/js/smooth-scroll.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/dist/js/smooth-scroll.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* smooth-scroll v9.1.4: Animate scrolling to anchor links
2+
* smooth-scroll v9.2.0: Animate scrolling to anchor links
33
* (c) 2016 Chris Ferdinandi
44
* MIT License
55
* http://github.com/cferdinandi/smooth-scroll
@@ -292,7 +292,7 @@
292292
location = Math.max(location - headerHeight - offset, 0);
293293
return Math.min(location, getDocumentHeight() - getViewportHeight());
294294
};
295-
295+
296296
/**
297297
* Determine the viewport's height
298298
* @private
@@ -437,9 +437,14 @@
437437
// If a smooth scroll link, animate it
438438
var toggle = getClosest( event.target, settings.selector );
439439
if ( toggle && toggle.tagName.toLowerCase() === 'a' ) {
440+
441+
// Check that link is an anchor and points to current page
442+
if ( toggle.origin !== location.origin || toggle.pathname !== location.pathname ) return;
443+
440444
event.preventDefault(); // Prevent default click event
441445
var hash = smoothScroll.escapeCharacters( toggle.hash ); // Escape hash characters
442446
smoothScroll.animateScroll( hash, toggle, settings); // Animate scroll
447+
443448
}
444449

445450
};
@@ -511,4 +516,4 @@
511516

512517
return smoothScroll;
513518

514-
});
519+
});

0 commit comments

Comments
 (0)