UNPKG

nyg-jam3

Version:

Jam3 project scaffold generator based on nyg

31 lines (24 loc) 755 B
import noop from 'no-op'; import animate from '../util/gsap-animate'; const defaultProps = { x: 0, y: 0, duration: 0, // in seconds ease: window.Quart.easeInOut }; let timeoutId; /** * Scroll page to a specific position * * @param {object} [props={}] - Scroll options. Refer to 'defaultProps' object * @param {function} [onComplete=noop] - On complete trigger function */ export default function scrollPage(props = {}, onComplete = noop) { const combinedProps = Object.assign({}, defaultProps, props); const { x, y, duration, ease } = combinedProps; timeoutId && clearTimeout(timeoutId); timeoutId = setTimeout(onComplete, duration * 1000); animate.to(window, duration, { scrollTo: { x, y, autoKill: false, ease } }); }