svelte-scrolling
Version:
Scroll to given elements with smooth animation
24 lines (23 loc) • 583 B
JavaScript
import smoothScroll from './smoothScroll';
const scrolling = async (coord, options) => {
const { duration, easing, offset } = options;
const startY = window.pageYOffset;
const startX = window.pageXOffset;
const endX = coord.x + offset;
const endY = coord.y + offset;
await smoothScroll({
start: {
x: startX,
y: startY
},
end: {
x: endX,
y: endY
},
duration,
easing
}, (coord) => {
window.scroll(coord.x, coord.y);
});
};
export default scrolling;