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

    Function toggleScrollLock

    • Toggles the scroll lock on the document body to prevent or allow scrolling.

      When locking scroll, it sets overflow: hidden on the <body> and adjusts padding-right to compensate for the scrollbar width, preventing layout shift. When unlocking, it restores the original styles.

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

      Parameters

      • lock: boolean

        If true, locks scrolling and adjusts padding. If false, restores scrolling and styles.

      Returns void

      void

      // ES Module
      import { toggleScrollLock } from '@bnidev/js-utils'
      // CommonJS

      const { toggleScrollLock } = require('@bnidev/js-utils')
      // Lock scroll (e.g., when opening a modal)
      toggleScrollLock(true)

      // Unlock scroll (e.g., when closing a modal)
      toggleScrollLock(false)