E5CE GitHub - zeusdeux/isInViewport: An ultra-light jQuery plugin that tells you if an element is in the viewport but with a twist.
[go: up one dir, main page]

Skip to content

An ultra-light jQuery plugin that tells you if an element is in the viewport but with a twist.

License

Notifications You must be signed in to change notification settings

zeusdeux/isInViewport

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

isInViewport.js

Build Status CDNJS

An ultra-light jQuery plugin that tells you if the element is in the viewport, but with a twist.

Did you say demo (inclusive of tests)?

For a more performant alternative, please take a look at observe-element-in-viewport which uses the new IntersectionObserver API. Please keep in mind that you might have to ship a polyfill for IntersectionObserver depending on the browsers you support.

Note: If you need this in a React application, please use the use-is-in-viewport hook.

Installation

Using in a module

npm install --save is-in-viewport

You can then require('is-in-viewport') or import 'is-in-viewport' in your code. It will automagically work with the bundler of your choice. If it breaks, please feel free to open an issue.

Example usage in an ES6/ES2015 module is shown in the examples/es6-example folder.

Note: isInViewport is a side-effecting module. It imports jquery that you have installed and attaches itself on it. As a consequence, isInViewport requires jquery to be installed as a peer dependency. Your bundling will fail if jquery isn't installed as is-in-viewport imports jquery.

Using directly in a script tag

  • Get the release that you want from releases/tags (or bower install isInViewport or npm install --save is-in-viewport)
  • Copy/link either isInViewport.js or isInViewport.min.js and the respective sourcemap from the lib folder to your folder containing your scripts
  • Add it after you include jQuery
  • You're ready to go!

Usage