With a customizable configuration
and a consistent cross browser behaviour.
> yarn add scroll-snap
import createScrollSnap from 'scroll-snap'
createScrollSnap(element, {
snapDestinationX: '90%',
timeout: 100,
duration: 300,
})
// Only snap once
const { unbind } = createScrollSnap(
element,
{
snapDestinationX: '90%',
timeout: 100,
duration: 300,
threshold: 0.2,
easing: (t: number) => (
t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t
)
},
() => unbind()
)