Dependency-free JavaScript library to detect when element enters into view
Switch branches/tags
Nothing to show
Clone or download
Permalink
Failed to load latest commit information.
.babelrc es6 and tweaks Jan 24, 2016
.eslintrc update code Apr 19, 2018
.gitignore update code Apr 19, 2018
LICENSE setup Dec 11, 2015
README.md Update README.md Jun 25, 2018
enter-view.js exit view Apr 26, 2018
enter-view.min.js exit view Apr 26, 2018
gulpfile.js es6 and tweaks Jan 24, 2016
index.html exit view Apr 26, 2018
package.json 1.0.0 Apr 26, 2018

README.md

enter-view.js

Dependency-free JavaScript library to detect when element enters into view. See demo. It uses requestAnimationFrame in favor of scroll events for less jank. Less than 1kb minified + gzipped.

Usage

enterView({
	selector: '.class-name',
	enter: function(el) {
		el.classList.add('entered');
	}
});
enterView({
	selector: '.class-name',
	enter: function(el) {
		el.classList.add('entered');
	},
	offset: 0.5, // enter at middle of viewport
	once: true, // trigger just once
});

Options

selector: [string or array of elements] required

Takes a class, id, or array of dom elements.

enter: [function] required

Callback function that returns the element that was entered.

exit: [function] optional

Callback function that returns the element that was exited.

offset: [number] optional (defaults to 0)

A value from 0 to 1 of how far from the bottom of the viewport to offset the trigger by. 0 = top of element crosses bottom of viewport (enters screen from bottom), 1 = top of element crosses top of viewport (exits screen top).

once: [boolean] optional (defaults to false)

Whether or not to trigger the callback just once.