Tweakr
    Preparing search index...

    Function scrollToTop

    • Scrolls the specified container to the top.

      Supports window or any HTMLElement with optional smooth scrolling and offset. Falls back to instant scroll if smooth scrolling is not supported.

      Parameters

      • container: HTMLElement | Window = window

        Scroll container (window or HTMLElement). Defaults to window.

      • behavior: ScrollBehavior = "smooth"

        Scroll behavior: "smooth" or "auto". Defaults to "smooth".

      • offset: number = 0

        Optional offset from top. Can be negative. Defaults to 0.

      Returns void

      scrollToTop(); // Scroll window smoothly to top

      const container = document.querySelector("#chat");
      if (container) scrollToTop(container, "auto", -20); // Scroll a div instantly with offset

      1.2.0