pinafore/src/routes/_utils/scrollToTop.js
Nolan Lawson 7c04b86405
fix: use smooth scroll polyfill in Chrome for scroll-to-top (#1601)
* fix: use smooth scroll polyfill in Chrome for scroll-to-top

* rename thunk to __thunk__ for safety
2019-10-24 19:03:10 -07:00

16 lines
411 B
JavaScript

import { getScrollContainer } from './scrollContainer'
import { smoothScroll } from './smoothScroll'
export function scrollToTop (smooth) {
const scroller = getScrollContainer()
const { scrollTop } = scroller
if (scrollTop === 0) {
return false
}
if (smooth) {
smoothScroll(scroller, 0, /* horizontal */ false, /* preferFast */ true)
} else {
scroller.scrollTop = 0
}
return true
}