Skip to content

Commit 7137076

Browse files
author
Chris Ferdinandi
committed
Extended overrides with settings
1 parent a8e8eda commit 7137076

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

smooth-scroll.js

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,21 +192,18 @@
192192
* @param {Object} settings
193193
* @param {Event} event
194194
*/
195-
exports.animateScroll = function ( toggle, anchor, settings, event ) {
195+
exports.animateScroll = function ( toggle, anchor, options, event ) {
196196

197197
// Options and overrides
198-
settings = extend( defaults, settings || {} ); // Merge user options with defaults
198+
var settings = extend( defaults, options || {} ); // Merge user options with defaults
199199
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 );
204201

205202
// Selectors and variables
206203
var fixedHeader = document.querySelector('[data-scroll-header]'); // Get the fixed header
207204
var headerHeight = fixedHeader === null ? 0 : (fixedHeader.offsetHeight + fixedHeader.offsetTop); // Get the height of a fixed header if one exists
208205
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
210207
var animationInterval; // interval timer
211208
var distance = endLocation - startLocation; // distance to travel
212209
var documentHeight = getDocumentHeight();
@@ -219,7 +216,7 @@
219216
}
220217

221218
// Update URL
222-
updateUrl(anchor, updateURL);
219+
updateUrl(anchor, settings.updateURL);
223220

224221
/**
225222
* Stop the scroll animation when it reaches its target (or the bottom/top of page)
@@ -242,9 +239,9 @@
242239
*/
243240
var loopAnimateScroll = function () {
244241
timeLapsed += 16;
245-
percentage = ( timeLapsed / speed );
242+
percentage = ( timeLapsed / parseInt(settings.speed, 10) );
246243
percentage = ( percentage > 1 ) ? 1 : percentage;
247-
position = startLocation + ( distance * easingPattern(easing, percentage) );
244+
position = startLocation + ( distance * easingPattern(settings.easing, percentage) );
248245
root.scrollTo( 0, Math.floor(position) );
249246
stopAnimateScroll(position, endLocation, animationInterval);
250247
};

0 commit comments

Comments
 (0)