11/* =============================================================
22
3- Smooth Scroll v4.4
3+ Smooth Scroll v4.5
44 Animate scrolling to anchor links, by Chris Ferdinandi.
55 http://gomakethings.com
66
@@ -21,6 +21,7 @@ window.smoothScroll = (function (window, document, undefined) {
2121 var _defaults = {
2222 speed : 500 ,
2323 easing : 'easeInOutCubic' ,
24+ offset : 0 ,
2425 updateURL : false ,
2526 callbackBefore : function ( ) { } ,
2627 callbackAfter : function ( ) { }
@@ -116,15 +117,16 @@ window.smoothScroll = (function (window, document, undefined) {
116117 // Options and overrides
117118 options = _mergeObjects ( _defaults , options || { } ) ; // Merge user options with defaults
118119 var overrides = _getDataOptions ( toggle ? toggle . getAttribute ( 'data-options' ) : null ) ;
119- var speed = overrides . speed || options . speed ;
120+ var speed = parseInt ( overrides . speed || options . speed , 10 ) ;
120121 var easing = overrides . easing || options . easing ;
122+ var offset = parseInt ( overrides . offset || options . offset , 10 ) ;
121123 var updateURL = overrides . updateURL || options . updateURL ;
122124
123125 // Selectors and variables
124126 var fixedHeader = document . querySelector ( '[data-scroll-header]' ) ; // Get the fixed header
125127 var headerHeight = fixedHeader === null ? 0 : ( fixedHeader . offsetHeight + fixedHeader . offsetTop ) ; // Get the height of a fixed header if one exists
126128 var startLocation = window . pageYOffset ; // Current location on the page
127- var endLocation = _getEndLocation ( document . querySelector ( anchor ) , headerHeight ) ; // Scroll to location
129+ var endLocation = _getEndLocation ( document . querySelector ( anchor ) , headerHeight + offset ) ; // Scroll to location
128130 var animationInterval ; // interval timer
129131 var distance = endLocation - startLocation ; // distance to travel
130132 var timeLapsed = 0 ;
0 commit comments