Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

in-view

Package Overview
Dependencies
Maintainers
1
Versions
17
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

in-view

Get notified when a DOM element enters or exits the viewport.

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
6.7K
increased by1.62%
Maintainers
1
Weekly downloads
 
Created
Source

in-view.js :eyes:

Get notified when a DOM element enters or exits the viewport. A small (~2kb gzipped), dependency-free, javascript utility for IE9+.

camwiegert.github.io/in-view

in-view.js


Installation

Either download the latest release and include it in your markup or install with npm:

npm install --save in-view

Basic Usage

With in-view, you can register handlers that are called when an element enters or exits the viewport. Each handler receives one element, the one entering or exiting the viewport, as its only argument.

inView('.someSelector')
    .on('enter', doSomething)
    .on('exit', el => {
        el.style.opacity = 0.5;
    });

Methods

in-view maintains a separate handler registry for each set of elements captured with inView(<selector>). Each registry exposes the same four methods. in-view also exposes two top-level methods. (is, offset).

inView(<selector>).on(<event>, <handler>)

Register a handler to the elements selected by selector for event. The only events the inView emits are 'enter' and 'exit'.

inView('.someSelector').on('enter', doSomething);

inView(<selector>).once(<event>, <handler>)

Register a handler to the elements selected by selector for event. Handlers registered with once will only be called once.

inView('.someSelector').once('enter', doSomething);

inView.is(<element>)

Check if element is in the viewport.

inView.is(document.querySelectorAll('.someSelector')[0]);
// => true

inView.offset(<integer>)

By default, in-view considers something in viewport if it breaks any edge of the viewport. This can be used to set an offset from that edge. For example, an offset of 100 will consider elements in viewport if they break any edge of the viewport by at least 100 pixels. integer can be positive or negative.

inView.offset(100);
inView.offset(-50);

inView(<selector>).check()

Manually check the status of the elements selected by selector. By default, all registries are checked on window's scroll, resize, and load events.

inView('.someSelector').check();

inView(<selector>).emit(<event>, <element>)

Manually emit event for any single element.

inView('.someSelector').emit('exit', document.querySelectorAll('.someSelector')[0]);

License MIT

FAQs

Package last updated on 19 Aug 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc