fix: disable smooth scroll for users who prefer reduced motion (#958)

This commit is contained in:
Nolan Lawson 2019-02-09 19:52:40 -08:00 committed by GitHub
parent 56f5a45221
commit 37c85ec7e2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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
@ -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'