npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@financial-times/o-element-visibility

v2.3.3

Published

Utility for monitoring elements visibility within the viewport

Downloads

11

Readme

o-element-visibility CircleCI MIT licensed

Utility for tracking element visibility within the viewport.

o-element-visibility is deprecated. Instead use Intersection Observer with a polyfill to support browsers without Intersection Observer.

Methods

o-element-visibility#init(selector)

Tracks the selected elements and reports the percentage of the element currently on the screen, changes to the percentage in view will fire events within the oVisibility namespace (see Events below).

If the selector argument is omitted [data-o-element-visibility-track] is used.

Note: Enabling element tracking will also attach all o-viewport events.

o-element-visibility#destroy()

Stop tracking all currently tracked elements.

Note: This will not stop listening to all the oViewport events.

o-element-visibility#track(element)

Pass an element to be tracked, returns a TrackedElement (see below).

o-element-visibility#updatePositions(force)

The position of an element is cached when we begin tracking, this will recache those values for every element currently being tracked.

Force will force an event to fire even if no change is detected.

Note: During scrolling this method is not run but is run on resize or orientation change

o-element-visibility#update(force)

Updates the current visibility status of all elements and fires events if change are detected.

Force will force an event to fire even if no change is detected.

Properties

o-element-visibility#tracked

An array of the currently tracked elements

TrackedElement

An instance of TrackedElement is returned by the track method. The instance contains information about the position of the element in the page and methods to calculate it's visibility:

inview: Boolean // the elements current visibility within the viewport
percentage: Number // the percentage of the element in view
rect: Object // the result of the last getBoundingClientRect run on this element
width: Number // the width of the element
height: Number // the height of the element
top: Number // the absolute top of the element
left: Number // the absolute left of the element
bottom: Number // the absolute bottom of the element
right: Number // the absolute right of the element
area: Number // the area of the element

updatePosition(force)

returns this

Same as above but for this TrackedElement only. Force will force an event to fire even if no change is detected.

update(force)

returns this

Same as above but for this TrackedElement only. Force will force an event to fire even if no change is detected.

inViewport()

returns this

Test if the element is currently in the viewport

percentInViewport()

returns this

Calculate the percentage of the element in the viewport

Events

Each of these custom events are fired on document.body. For each custom event event.detail.originalEvent contains a reference to the original browser event.

Additional properties in event.detail are detailed below:

oVisibility.visible

element: HTMLElement // or Node in < ie10
inviewport: Boolean // if the element is in the viewport
type: ['visibility', 'percentage', 'update'] // the reason the event fired, either because of visibility or percentage change, update means the function was run with force
percentInView: Number //  the percentage of the element that is visible

Note: inviewport can be true while percentage is 0, this means the element has a width or height of 0 but is within the viewport