Skip to content

Commit c7587df

Browse files
committed
Fix for issue 49: determining the document's height (cross-browser)
1 parent c2445fa commit c7587df

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

smooth-scroll.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ window.smoothScroll = (function (window, document, undefined) {
109109
}
110110
};
111111

112+
// Determine the document's height (cross-browser)
113+
// Fix for issue 49 (https://github.com/cferdinandi/smooth-scroll/issues/49)
114+
// Private method
115+
var _getDocumentHeight = function () {
116+
return Math.max(
117+
document.body.scrollHeight, document.documentElement.scrollHeight,
118+
document.body.offsetHeight, document.documentElement.offsetHeight,
119+
document.body.clientHeight, document.documentElement.clientHeight
120+
);
121+
};
122+
112123
// Start/stop the scrolling animation
113124
// Public method
114125
// Runs functions
@@ -145,7 +156,7 @@ window.smoothScroll = (function (window, document, undefined) {
145156
// Runs functions
146157
var _stopAnimateScroll = function (position, endLocation, animationInterval) {
147158
var currentLocation = window.pageYOffset;
148-
if ( position == endLocation || currentLocation == endLocation || ( (window.innerHeight + currentLocation) >= document.body.scrollHeight ) ) {
159+
if ( position == endLocation || currentLocation == endLocation || ( (window.innerHeight + currentLocation) >= _getDocumentHeight() ) ) {
149160
clearInterval(animationInterval);
150161
options.callbackAfter( toggle, anchor ); // Run callbacks after animation complete
151162
}

0 commit comments

Comments
 (0)