Skip to content

disableElementScroll

type: function
since: v2.6.0

The disableElementScroll function is a utility that temporarily locks the scroll position of an element, effectively disabling scrolling. This is particularly useful when you want to prevent scrolling on a specific element, such as during a modal or overlay.

Usage

import { disableElementScroll } from '@mustib/utils/browser';
disableElementScroll();

Definition

function disableElementScroll(options?: Partial<{
element: HTMLElement,
scrollbarElement?: HTMLElement | Document
}>): void { }

Parameters

  1. options
    type options = {
    element?: HTMLElement,
    scrollbarElement?: HTMLElement | Document
    };
    /* default value */
    const options = {
    element: document.body,
    scrollbarElement: document
    };
    • options.element
      • The element to disable scrolling on.
      • default:
        document.body
    • options.scrollbarElement
      • The element that actually contains the scrollbar.
      • It is used to calculate the scrollbar size.
      • This is important because the element you want to disable scrolling on may not be the one displaying the scrollbar.
      • For example, when disabling scroll on the body, the scrollbar is typically on the document, not the body itself.
      • Setting this property correctly prevents layout shifts or unwanted content movement.
      • default:
        document

Returns

type T = void;