Websites v4 docs v5.2.5
    Preparing search index...

    Function useScrollToTop

    • Hook that provides smooth scroll-to-top functionality with optional callback support.

      Scrolls the window to the top of the page and optionally executes a callback function when the scroll operation completes. Uses a scroll event listener to detect when the scroll position reaches the top (scrollY === 0).

      Parameters

      • options: UseScrollToTopOptions = {}

        Configuration options for the scroll behavior

        • behavior

          The scroll behavior: 'smooth', 'instant', or 'auto'. Defaults to 'smooth'

        • onScrollComplete

          Optional callback function that fires when scrolling to top completes

      Returns UseScrollToTopReturn

      Object containing scrollToTop function and isScrolling state

      // Basic usage
      const { scrollToTop } = useScrollToTop();

      // With callback
      const { scrollToTop, isScrolling } = useScrollToTop({
      onScrollComplete: () => {
      console.log('Reached the top!');
      }
      });

      // With instant scroll
      const { scrollToTop } = useScrollToTop({
      behavior: 'instant',
      onScrollComplete: () => {
      // Fires immediately for instant scrolling
      }
      });