1.2.2 • Published 4 years ago

detect-scroll-direction v1.2.2

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

Scroll direction

Simple library for detecting the scroll vertical direction.

LIVE DEMO

  • Provides a custom event scrollDirectionChange
  • Automatically adds classes to an element based on the direction scroll-direction-up or scroll-direction-down.
// YOU CAN PROVIDE AN OPTIONS OBJECT
const options = {
  target : document.getElementById('custom-scroll-container'),
  addClasses : false
};
new ScrollDirection(options);

// OR JUST NOTHING
// INITIALIZE AN INSTANCE
new ScrollDirection();

// YOU CAN NOW ACCESS THE CUSTOM EVENT FOR THE PROVIDED ELEMENT
window.addEventListener('scrollDirectionChange',function(ev){
  console.log(ev.detail.direction);
  // PRINTS "up" OR "down"
});

Options

target

Type : Element
Default : window

addClasses

Type : String or Falsy value Boolean Default : body

By default scroll-direction-up and scroll-direction-down will be added to the class list of the body. You can provide a different selector or a falsy value like '' or just false.

1.2.2

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.1

4 years ago

1.1.0

4 years ago

1.0.9

4 years ago

1.0.8

4 years ago

1.0.7

4 years ago

1.0.6

4 years ago

1.0.3

4 years ago

1.0.2

4 years ago

1.0.1

4 years ago