JavaScript Library To Detect If An Element Is In View – inView.js

Category: Javascript | February 24, 2016
Authorcronin4392
Last UpdateFebruary 24, 2016
LicenseMIT
Views2,578 views
JavaScript Library To Detect If An Element Is In View – inView.js

inView.js is a pure JavaScript library that watches for the scroll event and executes callbacks when an element is scrolled in or out of the viewport.

How to use it:

Just load the inView.js JavaScript file into your html document and we’re ready to go.

<script src="inView.js"></script>

Add the CSS class ‘inView’ to your element.

<img class="inView" src="1.jpg">

Execute callback functions if the image is scrolled into or out of the viewport.

var el = new inView(document.getElementById('inView'));
    el.onInView(function() {
        // do something
    });
    el.onOutView(function() {
        // do something
    });

You Might Be Interested In:


Leave a Reply