@render-props/scrollable
Version:
A state container which provides an interface for listening to the scroll event of its child component and providing valuable data about direction, distance, and more. It also provides convenience functions for scrollTo with optional animation.
22 lines (21 loc) • 438 B
JavaScript
import {interpolate} from '@render-props/utils'
export default function scrollTo(element, from, to, {duration, timing}) {
const scroller =
element === window
? window.scrollTo
: function(x, y) {
element.scrollTop = y
element.scrollLeft = x
}
interpolate(
function(values) {
scroller(values.x, values.y)
},
{
from,
to,
duration,
timing,
}
)
}