Skip to content

Commit

Permalink
fix: disable smooth scroll for users who prefer reduced motion (#958)
Browse files Browse the repository at this point in the history
  • Loading branch information
nolanlawson authored Feb 10, 2019
1 parent 56f5a45 commit 37c85ec
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/routes/_utils/smoothScroll.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { store } from '../_store/store'

// via https://github.com/tootsuite/mastodon/blob/f59ed3a4fafab776b4eeb92f805dfe1fecc17ee3/app/javascript/mastodon/scroll.js
const easingOutQuint = (x, t, b, c, d) =>
c * ((t = t / d - 1) * t * t * t * t + 1) + b
Expand Down Expand Up @@ -62,7 +64,10 @@ function testSupportsSmoothScroll () {
export const hasNativeSmoothScroll = process.browser && testSupportsSmoothScroll()

export function smoothScroll (node, topOrLeft, horizontal) {
if (hasNativeSmoothScroll) {
if (store.get().reduceMotion) {
// don't do smooth-scroll at all for users who prefer reduced motion
node[horizontal ? 'scrollLeft' : 'scrollTop'] = topOrLeft
} else if (hasNativeSmoothScroll) {
return node.scrollTo({
[horizontal ? 'left' : 'top']: topOrLeft,
behavior: 'smooth'
Expand Down

0 comments on commit 37c85ec

Please sign in to comment.