1.1.4 • Published 6 years ago
intheviewport v1.1.4
intheviewport
Tells us whether an element is in the viewport
Installation
npm install --save intheviewport
Test whether a given element is in the viewport
InTheViewport.check(element);
You can also define a proportion the element has to be within the viewport for it to return true, this defaults to 0.2 (20%).
InTheViewport.check(element, proportion);
Watch some elements and add/remove classes based on whether they are in the viewport
var example = new InTheViewport(selector, {
//options, defaults listed...
//the proportion the element has to be in the viewport to count as 'visible'
proportion: 0.2,
//the class added to an element once the item has been seen
seenClass: 'is-seen',
//the class toggled on the element depending on whether it is currently 'visible' or not
visibleClass: 'is-visible'
});
//initialise:
example.init();
Development
Modify the source and run:
npm run build