Function isScrollable

Returns true if the given element is scrollable in the given direction, or in either direction (if axis is not given).

It first checks whether the current scroll offset on the target along the given axis is non-0, and if so returns true immediately. Otherwise it will attempt to determine if it's scrollable using one of these methods (controlled by options.active):

  • passive check (default): Will examine clientWidth/Height, scrollWidth/Height as well as the computed overflow CSS property to try to determine if the target is scrollable. This is not 100% reliable but is safer than the active check
  • active check: Will attempt to scroll the target by 1px and examine if the scroll offset had changed, then revert it back to 0. This is a more reliable check, however it can cause issues in certain contexts. In particular, if a scroll on the target had just been initiated (but it's scroll offset was still 0), the scroll may be cancelled. Never use that inside scroll-based handlers.

NOTE: If the layout has been invalidated and not yet recalculated, this will cause a forced layout, so always waitForMeasureTime before calling this function when possible.

  • Parameters

    • element: Element
    • Optionaloptions: { active?: boolean; axis?: "x" | "y"; noCache?: boolean }
      • Optionalactive?: boolean

        If true, then if the target's current scroll offset is 0, it will attempt to scroll it rather than looking at its overflow.

      • Optionalaxis?: "x" | "y"

        One of "x" or "y" for horizontal or vertical scroll respectively. If not given, it checks both.

      • OptionalnoCache?: boolean

        By default the result of a check is cached for 1s and if there's already a cached result for this element, it is returned. Set this to true to disable checking the cache and also saving the result into the cache.

    Returns boolean