Skip to content

Disable page only with JavaScript from scrolling when a certain action happens.

License

Notifications You must be signed in to change notification settings

Valianton/ng-disable-scroll-nocss

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

NPM

What does it do

Sometimes when a certain action happens, for instance, main menu slides out, it is often desirable to prevent the main body from scrolling and only allow the menu to be scrollable.

This is fairly easy to do on desktop browsers, all that is needed is to set root container to be "overflow: hidden"; but things are not so easy on mobile, and can be very tricky.

This is where ng-disable-scroll-nocss directive comes in.

Install

  npm install --save ng-disable-scroll-nocss
  bower install --save ng-disable-scroll-nocss

How do I use it

It is very simple to use it.

  1. make your Angular app depends on ngDisableScrollNocss module
  angular.module("app", [
    "ngDisableScrollNocss"
  ]);

or with Browserify or Webpack

  angular.module("app", [
    require("ng-disable-scroll-nocss").name
  ]);
  1. add 'ng-disable-scroll-nocss' to one of the element, and specify an expression which will be evaluated to be truthy when scrolling should be prevented.

For example when menu is open

  <div ng-disable-scroll="menu.open">
  ...
  </div>
  1. optionally, can also specify which child element(s) are scrollable by providing an CSS selector; by default, the element where this directive is used will be used this is not specified.

One example use case is when there is a multi-level menu, only the second level menus are allowed to scroll

  <div ng-disable-scroll="menu.open" scrollable-elements=".second-level-menu">
  ...
  </div>

About

Disable page only with JavaScript from scrolling when a certain action happens.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%