Skip to content

Commit dd0553f

Browse files
committed
Iksi patch 1 (cferdinandi#255)
* Adjust EndLocation when out of scrollable range Adjust the EndLocation when it’s outside of the scrollable range by checking whether the calculated location is smaller than then document height minus the viewport height. * v9.1.4 Adjust the endLocation when it’s outside of the scrollable range
1 parent 7220207 commit dd0553f

File tree

6 files changed

+44
-17
lines changed

6 files changed

+44
-17
lines changed

dist/js/smooth-scroll.js

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* smooth-scroll v9.1.3: Animate scrolling to anchor links
2+
* smooth-scroll v9.1.4: Animate scrolling to anchor links
33
* (c) 2016 Chris Ferdinandi
44
* MIT License
55
* http://github.com/cferdinandi/smooth-scroll
@@ -289,9 +289,18 @@
289289
anchor = anchor.offsetParent;
290290
} while (anchor);
291291
}
292-
location = location - headerHeight - offset;
293-
return location >= 0 ? location : 0;
292+
location = Math.max(location - headerHeight - offset, 0);
293+
return Math.min(location, getDocumentHeight() - getViewportHeight());
294294
};
295+
296+
/**
297+
* Determine the viewport's height
298+
* @private
299+
* @returns {Number}
300+
*/
301+
var getViewportHeight = function() {
302+
return Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
303+
};
295304

296305
/**
297306
* Determine the document's height
@@ -502,4 +511,4 @@
502511

503512
return smoothScroll;
504513

505-
});
514+
});

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: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* smooth-scroll v9.1.2: Animate scrolling to anchor links
2+
* smooth-scroll v9.1.4: Animate scrolling to anchor links
33
* (c) 2016 Chris Ferdinandi
44
* MIT License
55
* http://github.com/cferdinandi/smooth-scroll
@@ -122,7 +122,7 @@
122122
}
123123

124124
// Get closest match
125-
for ( ; elem && elem !== document; elem = elem.parentNode ) {
125+
for ( ; elem && elem !== document && elem.nodeType === 1; elem = elem.parentNode ) {
126126

127127
// If selector is a class
128128
if ( firstChar === '.' ) {
@@ -289,9 +289,18 @@
289289
anchor = anchor.offsetParent;
290290
} while (anchor);
291291
}
292-
location = location - headerHeight - offset;
293-
return location >= 0 ? location : 0;
292+
location = Math.max(location - headerHeight - offset, 0);
293+
return Math.min(location, getDocumentHeight() - getViewportHeight());
294294
};
295+
296+
/**
297+
* Determine the viewport's height
298+
* @private
299+
* @returns {Number}
300+
*/
301+
var getViewportHeight = function() {
302+
return Math.max(document.documentElement.clientHeight, window.innerHeight || 0);
303+
};
295304

296305
/**
297306
* Determine the document's height
@@ -502,4 +511,4 @@
502511

503512
return smoothScroll;
504513

505-
});
514+
});

0 commit comments

Comments
 (0)