Skip to content

Commit 3157656

Browse files
committed
Fixed error when disabling scroll to top
1 parent 00c77a1 commit 3157656

File tree

8 files changed

+148
-10
lines changed

8 files changed

+148
-10
lines changed

dist/smooth-scroll.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* smooth-scroll v16.0.2
2+
* smooth-scroll v16.0.3
33
* Animate scrolling to anchor links
44
* (c) 2019 Chris Ferdinandi
55
* MIT License
@@ -525,7 +525,13 @@
525525
var hash = escapeCharacters(toggle.hash);
526526

527527
// Get the anchored element
528-
var anchor = settings.topOnEmptyHash && hash === '#' ? document.documentElement : document.querySelector(hash);
528+
var anchor;
529+
if (hash === '#') {
530+
if (!settings.topOnEmptyHash) return;
531+
anchor = document.documentElement;
532+
} else {
533+
anchor = document.querySelector(hash);
534+
}
529535
anchor = !anchor && hash === '#top' ? document.documentElement : anchor;
530536

531537
// If anchored element exists, scroll to it

dist/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.

dist/smooth-scroll.polyfills.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* smooth-scroll v16.0.2
2+
* smooth-scroll v16.0.3
33
* Animate scrolling to anchor links
44
* (c) 2019 Chris Ferdinandi
55
* MIT License
@@ -595,7 +595,13 @@ if (window.Element && !Element.prototype.closest) {
595595
var hash = escapeCharacters(toggle.hash);
596596

597597
// Get the anchored element
598-
var anchor = settings.topOnEmptyHash && hash === '#' ? document.documentElement : document.querySelector(hash);
598+
var anchor;
599+
if (hash === '#') {
600+
if (!settings.topOnEmptyHash) return;
601+
anchor = document.documentElement;
602+
} else {
603+
anchor = document.querySelector(hash);
604+
}
599605
anchor = !anchor && hash === '#top' ? document.documentElement : anchor;
600606

601607
// If anchored element exists, scroll to it

0 commit comments

Comments
 (0)