|
192 | 192 | * @param {Object} settings |
193 | 193 | * @param {Event} event |
194 | 194 | */ |
195 | | - exports.animateScroll = function ( toggle, anchor, settings, event ) { |
| 195 | + exports.animateScroll = function ( toggle, anchor, options, event ) { |
196 | 196 |
|
197 | 197 | // Options and overrides |
198 | | - settings = extend( defaults, settings || {} ); // Merge user options with defaults |
| 198 | + var settings = extend( defaults, options || {} ); // Merge user options with defaults |
199 | 199 | var overrides = getDataOptions( toggle ? toggle.getAttribute('data-options') : null ); |
200 | | - var speed = parseInt(overrides.speed || settings.speed, 10); |
201 | | - var easing = overrides.easing || settings.easing; |
202 | | - var offset = parseInt(overrides.offset || settings.offset, 10); |
203 | | - var updateURL = overrides.updateURL || settings.updateURL; |
| 200 | + settings = extend( settings, overrides ); |
204 | 201 |
|
205 | 202 | // Selectors and variables |
206 | 203 | var fixedHeader = document.querySelector('[data-scroll-header]'); // Get the fixed header |
207 | 204 | var headerHeight = fixedHeader === null ? 0 : (fixedHeader.offsetHeight + fixedHeader.offsetTop); // Get the height of a fixed header if one exists |
208 | 205 | var startLocation = root.pageYOffset; // Current location on the page |
209 | | - var endLocation = getEndLocation( document.querySelector(anchor), headerHeight, offset ); // Scroll to location |
| 206 | + var endLocation = getEndLocation( document.querySelector(anchor), headerHeight, parseInt(settings.offset, 10) ); // Scroll to location |
210 | 207 | var animationInterval; // interval timer |
211 | 208 | var distance = endLocation - startLocation; // distance to travel |
212 | 209 | var documentHeight = getDocumentHeight(); |
|
219 | 216 | } |
220 | 217 |
|
221 | 218 | // Update URL |
222 | | - updateUrl(anchor, updateURL); |
| 219 | + updateUrl(anchor, settings.updateURL); |
223 | 220 |
|
224 | 221 | /** |
225 | 222 | * Stop the scroll animation when it reaches its target (or the bottom/top of page) |
|
242 | 239 | */ |
243 | 240 | var loopAnimateScroll = function () { |
244 | 241 | timeLapsed += 16; |
245 | | - percentage = ( timeLapsed / speed ); |
| 242 | + percentage = ( timeLapsed / parseInt(settings.speed, 10) ); |
246 | 243 | percentage = ( percentage > 1 ) ? 1 : percentage; |
247 | | - position = startLocation + ( distance * easingPattern(easing, percentage) ); |
| 244 | + position = startLocation + ( distance * easingPattern(settings.easing, percentage) ); |
248 | 245 | root.scrollTo( 0, Math.floor(position) ); |
249 | 246 | stopAnimateScroll(position, endLocation, animationInterval); |
250 | 247 | }; |
|
0 commit comments