@bnidev/js-utils
    Preparing search index...

    Function lockBodyScroll

    • Locks scrolling on the document body to prevent background scroll.

      Sets overflow: hidden on the <body> and adjusts padding-right to compensate for the scrollbar width, preventing layout shift. Stores original styles in data-* attributes so they can be restored.

      This is useful for modal dialogs, sidebars, or any UI that requires disabling background scroll while keeping layout stable.

      Returns void

      void

      // ES Module
      import { lockBodyScroll } from '@bnidev/js-utils'
      // CommonJS
      const { lockBodyScroll } = require('@bnidev/js-utils')
      // Lock scroll (e.g., when opening a modal)
      lockBodyScroll()