Skip to content

Commit 31e7bc7

Browse files
committed
If reduce motion is enabled, still include header offset in anchor jump
1 parent 3157656 commit 31e7bc7

File tree

6 files changed

+31
-22
lines changed

6 files changed

+31
-22
lines changed

dist/smooth-scroll.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* smooth-scroll v16.0.3
2+
* smooth-scroll v16.1.0
33
* Animate scrolling to anchor links
44
* (c) 2019 Chris Ferdinandi
55
* MIT License
@@ -90,7 +90,7 @@
9090
* Check to see if user prefers reduced motion
9191
* @param {Object} settings Script settings
9292
*/
93-
var reduceMotion = function (settings) {
93+
var reduceMotion = function () {
9494
if ('matchMedia' in window && window.matchMedia('(prefers-reduced-motion)').matches) {
9595
return true;
9696
}
@@ -486,6 +486,12 @@
486486
// Update the URL
487487
updateURL(anchor, isNum, _settings);
488488

489+
// If the user prefers reduced motion, jump to location
490+
if (reduceMotion()) {
491+
window.scrollTo(0, Math.floor(endLocation));
492+
return;
493+
}
494+
489495
// Emit a custom event
490496
emitEvent('scrollStart', _settings, anchor, toggle);
491497

@@ -500,9 +506,6 @@
500506
*/
501507
var clickHandler = function (event) {
502508

503-
// Don't run if the user prefers reduced motion
504-
if (reduceMotion(settings)) return;
505-
506509
// Don't run if event was canceled but still bubbled up
507510
// By @mgreter - https://github.com/cferdinandi/smooth-scroll/pull/462/
508511
if (event.defaultPrevented) return;
@@ -512,7 +515,7 @@
512515

513516
// Check if event.target has closest() method
514517
// By @totegi - https://github.com/cferdinandi/smooth-scroll/pull/401/
515-
if(!('closest' in event.target))return;
518+
if (!('closest' in event.target)) return;
516519

517520
// Check if a smooth scroll link was clicked
518521
toggle = event.target.closest(selector);

dist/smooth-scroll.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/smooth-scroll.polyfills.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*!
2-
* smooth-scroll v16.0.3
2+
* smooth-scroll v16.1.0
33
* Animate scrolling to anchor links
44
* (c) 2019 Chris Ferdinandi
55
* MIT License
@@ -160,7 +160,7 @@ if (window.Element && !Element.prototype.closest) {
160160
* Check to see if user prefers reduced motion
161161
* @param {Object} settings Script settings
162162
*/
163-
var reduceMotion = function (settings) {
163+
var reduceMotion = function () {
164164
if ('matchMedia' in window && window.matchMedia('(prefers-reduced-motion)').matches) {
165165
return true;
166166
}
@@ -556,6 +556,12 @@ if (window.Element && !Element.prototype.closest) {
556556
// Update the URL
557557
updateURL(anchor, isNum, _settings);
558558

559+
// If the user prefers reduced motion, jump to location
560+
if (reduceMotion()) {
561+
window.scrollTo(0, Math.floor(endLocation));
562+
return;
563+
}
564+
559565
// Emit a custom event
560566
emitEvent('scrollStart', _settings, anchor, toggle);
561567

@@ -570,9 +576,6 @@ if (window.Element && !Element.prototype.closest) {
570576
*/
571577
var clickHandler = function (event) {
572578

573-
// Don't run if the user prefers reduced motion
574-
if (reduceMotion(settings)) return;
575-
576579
// Don't run if event was canceled but still bubbled up
577580
// By @mgreter - https://github.com/cferdinandi/smooth-scroll/pull/462/
578581
if (event.defaultPrevented) return;
@@ -582,7 +585,7 @@ if (window.Element && !Element.prototype.closest) {
582585

583586
// Check if event.target has closest() method
584587
// By @totegi - https://github.com/cferdinandi/smooth-scroll/pull/401/
585-
if(!('closest' in event.target))return;
588+
if (!('closest' in event.target)) return;
586589

587590
// Check if a smooth scroll link was clicked
588591
toggle = event.target.closest(selector);

0 commit comments

Comments
 (0)