0.0.2 • Published 5 years ago

op-inview v0.0.2

Weekly downloads
5
License
MIT
Repository
github
Last release
5 years ago

op-inview

Trigger function / add class when element is in & out of the viewport.

Install

npm install op-inview
yarn add op-inview

Usage

import OpInview from 'op-inview';

To create a new inview instance:

const config = {
    el: document.querySelector('.inview')
};

const inview = OpInview.create(config);

It accepts a config object.

TypeNameDefault ValueDescription
Dom nodeelundefined (required)Dom element to track
Floatstart0.2Start position of inview trigger range, when scrolling the page down. Using opViewProgress to track elements progress in the viewport
Floatend0.8End position of inview trigger range, when scrolling the page down.
StringclassEnteris-inview-enterClass to apply when inview node entered the trigger range. If set to null, class wont be triggered. Has a dublicate class applied with -top or -bottom modifier, depending on element appearance position.
StringclassExitis-inview-exitSame as above, but triggered on exit of range.
BooleandeactivatefalseIf set to true will deactivate inview, when exited, thus allowing reenter. If set to false, will enter once, and remove itself
FunctiononEnterCallbackundefinedFunction to be called on enter. Receives an object { value, direction }, where value is progress.value when function is called and direction = top or bottom, depending on element appearance position.
FunctiononExitCallbackundefinedSame as above, but called on exit

Enable inline

Enables inline html quick add. For when you just want to use basic add / remove inview class functionality.

OpInview.inline();

Include in HTML. Use op-inview attribute, include JSON object with the config within. (No need to provide el)

<div op-inview='{"start": 0, "end": 1}'></div>