Function scrollTo

  • Smoothly scroll to the specified top and left coordinates inside the given container. Supports promises to handle the end of the scroll animation.

    Parameters

    Returns Promise<void>

    Example

    // Scroll with a static duration
    scrollTo({
    container: window,
    top: 500,
    duration: 500,
    });

    // Scroll with a dynamic duration based on distance
    scrollTo({
    top: 1000,
    duration: (px) => px,
    });

    // Use promise to handle when the scroll finishes
    scrollTo({ top: 500 })
    .then(() => console.log('Scroll complete'))
    .catch(() => console.error('Scroll failed'));