Skip to content

getScrollbarWidth

type: function
since: v1.0.5

The getScrollbarWidth function is used to get the scrollbar width of an element on a given direction.

The getScrollbarWidthErrorScope app error scope array is exported by this utility and can be used to filter thrown AppError by scope for this specific utility.
To learn more about error handling please refer to error handling section of the getting started guide, and the AppError documentation.

Usage

import { getScrollbarWidth } from '@mustib/utils/browser';
const scrollbarWidth = getScrollbarWidth();
console.log(scrollbarWidth);

Definition

function getScrollbarWidth(options?: Partial<{
element: Element | Document | null,
direction: 'x' | 'y',
}>): number { }

Parameters

  1. options
    since: v2.6.0
    type options = {
    element?: Element | Document | null,
    direction?: 'x' | 'y',
    };
    /* default value */
    const options = { element = document, direction = 'y' };
    • options.element
      • The element to get the scrollbar width from.
      • default:
        document
    • options.direction
      • The direction to get the scrollbar width from.
      • 'x' for horizontal, 'y' for vertical.
      • default:
        'y'

Returns

type T = number;
  • The scrollbar width in pixels.