rescript-body-scroll-lock

3.1.0 • Public • Published

rescript-body-scroll-lock

ReScript bindings for body-scroll-lock.

Exposed as BodyScrollLock module.

rescript-body-scroll-lock X.y.* means it's compatible with body-scroll-lock X.y.* version.

Installation

npm install body-scroll-lock rescript-body-scroll-lock

rescript-body-scroll-lock should be added to bs-dependencies in your bsconfig.json:

{
  //...
  "bs-dependencies": [
    // ...
+   "rescript-body-scroll-lock"
  ],
  //...
}

Methos

disableBodyScroll

Disables body scroll while enabling scroll on target element

open Webapi.Dom
switch document |> Document.querySelector(".js-scrollable-modal") {
| Some(scrollableModalEl) => BodyScrollLock.disableBodyScroll(scrollableModalEl, ())
| None => () // do nothing
}

enableBodyScroll

Enables body scroll and removing listeners on target element

open Webapi.Dom
switch document |> Document.querySelector(".js-scrollable-modal") {
| Some(scrollableModalEl) => BodyScrollLock.enableBodyScroll(scrollableModalEl)
| None => () // do nothing
}

clearAllBodyScrollLocks

Clears all scroll locks

clearAllBodyScrollLocks()

BodyScrollOptions

reserveScrollBarGap

optional, default: as in library

BodyScrollLock.disableBodyScroll(
  targetElement,
  ~options=BodyScrollLock.bodyScrollOptions(~reserveScrollBarGap=true, ()),
  (),
)

allowTouchMove

optional, default: as in library

BodyScrollLock.disableBodyScroll(
  el,
  ~options=BodyScrollLock.bodyScrollOptions(
    ~allowTouchMove=el => {el |> Webapi.Dom.Element.hasAttribute("data-with-scroll")},
    (),
  ),
  (),
)

/rescript-body-scroll-lock/

    Package Sidebar

    Install

    npm i rescript-body-scroll-lock

    Weekly Downloads

    1

    Version

    3.1.0

    License

    MIT

    Unpacked Size

    4.41 kB

    Total Files

    6

    Last publish

    Collaborators

    • dzakh-dev
    • dzakh