@@ -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}
@@ -109,17 +120,6 @@ window.smoothScroll = (function (window, document, undefined) {
109120 }
110121 } ;
111122
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-
123123 // Start/stop the scrolling animation
124124 // Public method
125125 // Runs functions
@@ -140,6 +140,7 @@ window.smoothScroll = (function (window, document, undefined) {
140140 var endLocation = _getEndLocation ( document . querySelector ( anchor ) , headerHeight + offset ) ; // Scroll to location
141141 var animationInterval ; // interval timer
142142 var distance = endLocation - startLocation ; // distance to travel
143+ var documentHeight = _getDocumentHeight ( ) ;
143144 var timeLapsed = 0 ;
144145 var percentage , position ;
145146
@@ -156,7 +157,7 @@ window.smoothScroll = (function (window, document, undefined) {
156157 // Runs functions
157158 var _stopAnimateScroll = function ( position , endLocation , animationInterval ) {
158159 var currentLocation = window . pageYOffset ;
159- if ( position == endLocation || currentLocation == endLocation || ( ( window . innerHeight + currentLocation ) >= _getDocumentHeight ( ) ) ) {
160+ if ( position == endLocation || currentLocation == endLocation || ( ( window . innerHeight + currentLocation ) >= documentHeight ) ) {
160161 clearInterval ( animationInterval ) ;
161162 options . callbackAfter ( toggle , anchor ) ; // Run callbacks after animation complete
162163 }
0 commit comments