How to use the body-scroll-lock.disableBodyScroll function in body-scroll-lock

To help you get started, we’ve selected a few body-scroll-lock examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github museui / muse-ui / src / internal / mixins / popup / manager.js View on Github external
preventScrolling () {
    if (this.locked) return;
    // body 操作
    const body = document.getElementsByTagName('body')[0];
    disableBodyScroll(body, {
      reserveScrollBarGap: true,
      allowTouchMove: (el) => {
        for (let i = 0; i < this.instances.length; i++) {
          if (
            this.instances[i] &&
            this.instances[i].$el &&
            this.instances[i].$el.contains(el)
          ) {
            return true;
          }
        }
        return false;
      }
    });
    this.locked = true;
  },
github thorgate / tg-modal / src / components / Modal.js View on Github external
// Increment modal count when opening.
            if (state) {
                numberOfModalsOpen += 1;
            }

            // Add toggle body class and update body padding if there is only one modal open.
            if (numberOfModalsOpen === 1) {
                // Toggle open class.
                toggleClass(body, 'tg-modal-open', state);

                const { bodyScrollLock } = this.props;

                if (state) {
                    if (bodyScrollLock && this.node.current) {
                        disableBodyScroll(this.node.current, {
                            reserveScrollBarGap: true,
                        });
                    }
                } else if (bodyScrollLock && this.node.current) {
                    clearAllBodyScrollLocks();
                }
            }

            // Decrement modal count when closing.
            if (!state) {
                numberOfModalsOpen = Math.max(numberOfModalsOpen - 1, 0);
            }
        }
    }
github qantasairways / runway / src / shared / ButtonWithDialog / components / Dialog.js View on Github external
lockBgScroll = () => {
    const { scrollTarget } = this.props;
    disableBodyScroll(scrollTarget);
  };
github andrewscwei / aristotl / src / components / Modal.tsx View on Github external
componentDidMount() {
    if (this.nodeRefs.scrollTarget.current) disableBodyScroll(this.nodeRefs.scrollTarget.current);
  }
github dpc-sdp / ripple / packages / components / Organisms / SiteHeader / index.vue View on Github external
this.$nextTick(function () {
          this.menuEl = document.querySelector('.rpl-site-header__menu-container')
          if (this.menuEl) {
            disableBodyScroll(this.menuEl)
          }
        })
      } else {
github reg-viz / reg-cli-report-ui / src / components / Sidebar / internal / Mobile / Mobile.tsx View on Github external
useEffect(() => {
    const { current: wrapper } = wrapperRef;
    const { current: focus } = focusRef;
    if (wrapper == null || focus == null) {
      return;
    }

    if (sidebar.isOpen) {
      focus.activate();
      disableBodyScroll(wrapper);
    } else {
      focus.deactivate();
      enableBodyScroll(wrapper);
    }
  }, [sidebar.isOpen]);
github poketo / poketo-reader / src / components / panel.js View on Github external
componentDidUpdate(prevProps: PanelProps) {
    if (prevProps.isShown !== this.props.isShown) {
      if (this.props.isShown === false) {
        clearAllBodyScrollLocks();
      } else if (this.scrollEl) {
        disableBodyScroll(this.scrollEl);
      }
    }
  }
github janczizikow / janczizikow-portfolio / src / components / MobileMenu / MobileMenu.js View on Github external
useEffect(() => {
    if (isMobileMenuOpen) {
      disableBodyScroll(menuRef.current);
    } else {
      enableBodyScroll(menuRef.current);
    }

    return () => {
      clearAllBodyScrollLocks();
    };
  }, [isMobileMenuOpen, menuRef]);
github cozy / cozy-ui / react / Overlay / index.jsx View on Github external
componentDidMount() {
    if (bodyTallerThanWindow()) {
      disableBodyScroll(document.body)
      disableBodyScroll(document.body.parentNode)
    }
    if (this.props.onEscape) {
      document.addEventListener('keydown', this.handleKeydown)
    }
  }
github aholachek / mobile-first-animation / src / MusicDrawer / index.js View on Github external
event.preventDefault()

      const drawerIsOpen = y.value === stops[1]

      const isClick =
        last && Math.abs(movementX) + Math.abs(movementY) <= 3 && !drawerIsOpen

      if (isClick) return setDrawerOpen()

      if (!memo) {
        const isIntentionalGesture =
          Math.abs(movementY) > threshold &&
          Math.abs(movementY) > Math.abs(movementX)

        if (!isIntentionalGesture) return
        disableBodyScroll(nowPlayingDrawerRef.current)
        memo = y.value - movementY
      }

      if (last) {
        enableBodyScroll(nowPlayingDrawerRef.current)

        const projectedEndpoint = y.value + projection(velocityY)
        const point = findNearestNumberInArray(projectedEndpoint, stops)

        return set({
          y: point,
          immediate: false,
          config: spring
        })
      }

body-scroll-lock

Enables body scroll locking (for iOS Mobile and Tablet, Android, desktop Safari/Chrome/Firefox) without breaking scrolling of a target element (eg. modal/lightbox/flyouts/nav-menus)

MIT
Latest version published 3 years ago

Package Health Score

69 / 100
Full package analysis