Pinafore-Web-Client-Frontend/src/routes/_utils/scrollToTop.js

17 lines
411 B
JavaScript
Raw Normal View History

import { getScrollContainer } from './scrollContainer'
import { smoothScroll } from './smoothScroll'
export function scrollToTop (smooth) {
2019-08-03 22:49:37 +02:00
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
}