fix: disable smooth scroll for users who prefer reduced motion (#958)
This commit is contained in:
parent
56f5a45221
commit
37c85ec7e2
|
@ -1,3 +1,5 @@
|
||||||
|
import { store } from '../_store/store'
|
||||||
|
|
||||||
// via https://github.com/tootsuite/mastodon/blob/f59ed3a4fafab776b4eeb92f805dfe1fecc17ee3/app/javascript/mastodon/scroll.js
|
// via https://github.com/tootsuite/mastodon/blob/f59ed3a4fafab776b4eeb92f805dfe1fecc17ee3/app/javascript/mastodon/scroll.js
|
||||||
const easingOutQuint = (x, t, b, c, d) =>
|
const easingOutQuint = (x, t, b, c, d) =>
|
||||||
c * ((t = t / d - 1) * t * t * t * t + 1) + b
|
c * ((t = t / d - 1) * t * t * t * t + 1) + b
|
||||||
|
@ -62,7 +64,10 @@ function testSupportsSmoothScroll () {
|
||||||
export const hasNativeSmoothScroll = process.browser && testSupportsSmoothScroll()
|
export const hasNativeSmoothScroll = process.browser && testSupportsSmoothScroll()
|
||||||
|
|
||||||
export function smoothScroll (node, topOrLeft, horizontal) {
|
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({
|
return node.scrollTo({
|
||||||
[horizontal ? 'left' : 'top']: topOrLeft,
|
[horizontal ? 'left' : 'top']: topOrLeft,
|
||||||
behavior: 'smooth'
|
behavior: 'smooth'
|
||||||
|
|
Loading…
Reference in New Issue