Scroll smoothly over time to a given absolute scroll position defined by the top and left properties.
If the top or left scroll position is omitted it will fallback to the current scroll position.
duration: Scroll duration in milliseconds; defaults to 0 (no transition)
element: The html element that should be scrolled; defaults to the main scrolling element
easingFunction: Defines the scrolling rate over time; defaults to ease in and out sin.
You can either use one of the predefined functions from EASING_FUNCTIONS or a custom one.
function smoothScrollTo({
top,
left,
duration = 0,
element = document.scrollingElement,
easingFunction = EASING_FUNCTIONS.slowInSlowOut
})
smoothScrollToTop({
duration = 0,
easingFunction = EASING_FUNCTIONS.slowInSlowOut
})
smoothScrollToBottom({
duration = 0,
easingFunction = EASING_FUNCTIONS.slowInSlowOut
})
smoothScrollToElement(element, {
duration, easingFunction,
offsetTop = 0,
offsetLeft = 0
})
smoothScrollToId(id, {
duration, easingFunction,
offsetTop = 0,
offsetLeft = 0,
})