Skip to main content
cngx-src documentation

createScrollLock

Functioncommon/layoutv0.1.0

projects/common/layout/scroll/scroll-lock-core.ts

Description#

Acquire a ref-counted scroll lock on a document root and get back the matching release function.

The first active lock saves the current overflow / scrollbar-gutter inline styles and sets overflow: hidden + scrollbar-gutter: stable (no layout shift when the scrollbar disappears). Releasing the last active lock restores the saved values. The returned release function is idempotent - calling it twice cannot over-decrement the count.

Shared engine behind CngxScrollLock and CngxDialog's modal scroll lock; consumers composing their own overlay primitives can use it directly.

const release = createScrollLock(document.documentElement);
// ... overlay open ...
release();

Signature#

createScrollLock(html: HTMLElement)

Parameters#

@paramhtmlHTMLElement
  • The document root (document.documentElement) to lock.

Returns#

void

Release function for this acquisition. Idempotent.