@@ -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