Skip to content

Commit b065f1f

Browse files
author
Chris Ferdinandi
committed
Merge branch 'pr/53'
2 parents 098628e + c58b618 commit b065f1f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ Smooth Scroll is licensed under the [MIT License](http://gomakethings.com/mit/).
185185

186186

187187
## Changelog
188+
* v4.6 - March 21, 2014
189+
* [Fixed scroll-to-top bug for links at the bottom of the page](https://github.com/cferdinandi/smooth-scroll/issues/49).
188190
* v4.5 - March 20, 2014
189191
* Added `offset` to `options`
190192
* v4.4 - March 15, 2014

smooth-scroll.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,17 @@ window.smoothScroll = (function (window, document, undefined) {
7575
}
7676
};
7777

78+
// Determine the document's height
79+
// Private method
80+
// Returns an integer
81+
var _getDocumentHeight = function () {
82+
return Math.max(
83+
document.body.scrollHeight, document.documentElement.scrollHeight,
84+
document.body.offsetHeight, document.documentElement.offsetHeight,
85+
document.body.clientHeight, document.documentElement.clientHeight
86+
);
87+
};
88+
7889
// Convert data-options attribute into an object of key/value pairs
7990
// Private method
8091
// Returns an {object}
@@ -129,6 +140,7 @@ window.smoothScroll = (function (window, document, undefined) {
129140
var endLocation = _getEndLocation( document.querySelector(anchor), headerHeight, offset ); // Scroll to location
130141
var animationInterval; // interval timer
131142
var distance = endLocation - startLocation; // distance to travel
143+
var documentHeight = _getDocumentHeight();
132144
var timeLapsed = 0;
133145
var percentage, position;
134146

@@ -145,7 +157,7 @@ window.smoothScroll = (function (window, document, undefined) {
145157
// Runs functions
146158
var _stopAnimateScroll = function (position, endLocation, animationInterval) {
147159
var currentLocation = window.pageYOffset;
148-
if ( position == endLocation || currentLocation == endLocation || ( (window.innerHeight + currentLocation) >= document.body.scrollHeight ) ) {
160+
if ( position == endLocation || currentLocation == endLocation || ( (window.innerHeight + currentLocation) >= documentHeight ) ) {
149161
clearInterval(animationInterval);
150162
options.callbackAfter( toggle, anchor ); // Run callbacks after animation complete
151163
}

0 commit comments

Comments
 (0)