viewport-visible

1.0.0 • Public • Published

viewport-visible Module

npm version

A light-weight module that allows you to pass in an element or elements and return whether or not they are visible within the immediate viewport.

Install

npm install viewport-visible --save-dev

Documentation

parameter

{
  target                List of elements OR a specific element you wish to check is within the viewport
  percent   [optional]  Integer from 0-100 of how much the element should be showing before returning true/false (default: 50)
  axis      [optional]  Specify axis in which to check if element is within the viewport (default: both)
  debug     [optional]  See console.logs (default: false)
}

How to call: 

var vizObj = inViewport({
  target    : document.querySelectorAll('.className'),
  percent   : 50,
  axis      : 'x||y||both'
});

Returns: obj of arrays that is separated into visible, nonvisible, and then all
         all obj in the format of { el : el1, visible : true }
{
  visible     : [el1]
  nonvisibile : [el2]
  all         : [ {el1, true}, {el2, false} ]
}

Where now you can call vizObj.all, vizObj.visible, vizObj.nonvisible

Package Sidebar

Install

npm i viewport-visible

Weekly Downloads

1

Version

1.0.0

License

MIT

Unpacked Size

5.63 kB

Total Files

3

Last publish

Collaborators

  • augbog
  • ryanburgess