Socket
Book a DemoInstallSign in
Socket

body-scroll-toggle

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

body-scroll-toggle

Enables / disables scroll on the body

latest
Source
npmnpm
Version
0.2.0
Version published
Weekly downloads
692
11.79%
Maintainers
1
Weekly downloads
 
Created
Source

Body scroll toggle

Disables scroll-ability of the body, like you'd want when a fixed position modal is open, by logging the current scroll position and then making the body position fixed using that scroll offset of the body top. Thus, the user shouldn't see the body shift position. Many approaches just overflow:hidden on the body, but this does not disable scrolling in iOS.

const bodyScroll = require('body-scroll-toggle')
bodyScroll.disable()
bodyScroll.enable()

A disadvantage of this approach is that the iOS bottom nav bar will get re-displayed when the scroll is disabled.

Alternatives

There are JS event.preventDefault() based approaches like:

  • https://github.com/gilbarbara/disable-scroll
  • https://github.com/ultrapasty/jquery-disablescroll

These work but will prevent scrolling of internal elements that have an overflow:scroll, which is often the case in mobile navs.

Contributing

Run npm version <newversino> && npm publish to push new builds up.

FAQs

Package last updated on 06 Sep 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts