11/*!
2- * smooth-scroll v14.1.1 : Animate scrolling to anchor links
2+ * smooth-scroll v14.2.0 : Animate scrolling to anchor links
33 * (c) 2018 Chris Ferdinandi
44 * MIT License
55 * http://github.com/cferdinandi/smooth-scroll
@@ -101,6 +101,7 @@ if (window.Element && !Element.prototype.closest) {
101101
102102 // Speed & Easing
103103 speed : 500 ,
104+ clip : true ,
104105 offset : 0 ,
105106 easing : 'easeInOutCubic' ,
106107 customEasing : null ,
@@ -324,12 +325,14 @@ if (window.Element && !Element.prototype.closest) {
324325
325326 /**
326327 * Calculate how far to scroll
327- * @param {Element } anchor The anchor element to scroll to
328- * @param {Number } headerHeight Height of a fixed header, if any
329- * @param {Number } offset Number of pixels by which to offset scroll
328+ * Clip support added by robjtede - https://github.com/cferdinandi/smooth-scroll/issues/405
329+ * @param {Element } anchor The anchor element to scroll to
330+ * @param {Number } headerHeight Height of a fixed header, if any
331+ * @param {Number } offset Number of pixels by which to offset scroll
332+ * @param {Boolean } clip If true, adjust scroll distance to prevent abrupt stops near the bottom of the page
330333 * @returns {Number }
331334 */
332- var getEndLocation = function ( anchor , headerHeight , offset ) {
335+ var getEndLocation = function ( anchor , headerHeight , offset , clip ) {
333336 var location = 0 ;
334337 if ( anchor . offsetParent ) {
335338 do {
@@ -338,7 +341,10 @@ if (window.Element && !Element.prototype.closest) {
338341 } while ( anchor ) ;
339342 }
340343 location = Math . max ( location - headerHeight - offset , 0 ) ;
341- return location ;
344+ if ( clip ) {
345+ location = Math . min ( location , getDocumentHeight ( ) - window . innerHeight ) ;
346+ }
347+ return location ;
342348 } ;
343349
344350 /**
@@ -475,7 +481,7 @@ if (window.Element && !Element.prototype.closest) {
475481 // Get the height of a fixed header if one exists and not already set
476482 headerHeight = getHeaderHeight ( fixedHeader ) ;
477483 }
478- var endLocation = isNum ? anchor : getEndLocation ( anchorElem , headerHeight , parseInt ( ( typeof animateSettings . offset === 'function' ? animateSettings . offset ( anchor , toggle ) : animateSettings . offset ) , 10 ) ) ; // Location to scroll to
484+ var endLocation = isNum ? anchor : getEndLocation ( anchorElem , headerHeight , parseInt ( ( typeof animateSettings . offset === 'function' ? animateSettings . offset ( anchor , toggle ) : animateSettings . offset ) , 10 ) , animateSettings . clip ) ; // Location to scroll to
479485 var distance = endLocation - startLocation ; // distance to travel
480486 var documentHeight = getDocumentHeight ( ) ;
481487 var timeLapsed = 0 ;
0 commit comments