element-listener-js

0.3.0 • Public • Published

Build Status

Element Listener

A light-weight library that allows you to detect some extremely useful events on DOM Elements that have not otherwise been made available in the standard web events.

Usage

Detect when an element is scrolled in and out of view

You can detect when an element on a web page is scrolled in and out of the browser's viewport. It supports scrolling in all directions (up, down, left, right) including offsets. The following is a simple example, assuming you already have an element on your page with an id of my-element...

var elementListener = new ElementListener({
    el: document.getElementById('my-element'),
    onEnterView: function () {
       // element has been scrolled into view!
    },
    onExitView: function () {
       // element has been scrolled out of view!
    }
});

Package Sidebar

Install

npm i element-listener-js

Weekly Downloads

1

Version

0.3.0

License

MIT

Last publish

Collaborators

  • npm