🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

element-is-visible-in-viewport

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

element-is-visible-in-viewport

Tells you if an element is visible (vertically only) in the viewport.

2.0.0
latest
npm
Version published
Weekly downloads
23
-64.06%
Maintainers
1
Weekly downloads
 
Created
Source

Element is visible in viewport.

Tells you if an element is visible (vertically only) in the viewport.

Use it like

The method exported takes 3 arguments:

  • The element in question.
  • OPTIONAL - The Mode.
    • 'above' - Tells you if the viewport is above the element.
    • 'below' - Tells you if the viewport is below the element.
    • 'visible' - DEFAULT - Tells you if the element is totally within the viewport.
    • 'any' - Tells you if any part of the element is visible in the viewport.
  • OPTIONAL - 'threshold' - in pixels around the element from which you want to determine if it is visible. Useful if you want to do something right before the element comes into view. Default = 0.
// Using no Mode.
checkVisible(document.querySelector('.something')) && console.log('ELEMENT IS TOTALLY VISIBLE IN THE VIEWPORT');

// Using the MODE.
checkVisible(document.querySelector('.something'), 'above') && console.log('ELEMENT IS ABOVE THE VIEWPORT');
checkVisible(document.querySelector('.something'), 'below') && console.log('ELEMENT IS BELOW THE VIEWPORT');
checkVisible(document.querySelector('.something'), 'visible') && console.log('ELEMENT IS TOTALLY THE VIEWPORT');
checkVisible(document.querySelector('.something'), 'any') && console.log('SOME PART OF THE ELEMENT IS VISIBLE');

Inspired by thanks to stack overflow user Tokimon.

I made this lib because lately I have been writing a ton of stuff that needs to know if it is in the viewport or not. I got tired or copy and pasting that code mentioned above.

FAQs

Package last updated on 09 May 2016

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