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

@cevad-tokatli/dom-display-detector

v1.0.0

Published

DOM Display Detector detects an element if it is displayed on the screen or not and calls the given callback method according to the view status.

Downloads

4

Readme

DOM Display Detector

DOM Display Detector detects an element if it is displayed on the screen or not and calls the given callback method according to the view status.

Click here to see the demo.

Installation

It is available as a package on NPM for use with a module bundler.

# NPM
$ npm install --save @cevad-tokatli/dom-display-detector

# Yarn
$ yarn add @cevad-tokatli/dom-display-detector

Usage

You can simply import the module and call bind method to bind an element to DOM Display Detector.

import { bind } from '@cevad-tokatli/dom-display-detector'

const el = document.querySelector('#el')
bind(el, () => {
    el.classList.add('active')
})

Methods

bind

bind(el: Element | HTMLElement | string, onShow: (el: HTMLElement, isInitial: boolean) => void, onHide?: (el: HTMLElement, isInitial: boolean) => void): void

Binds the given element(s) to DOM Display Detector. Every time the element appears on the screen, calls onShow method and when the element disappears on the screen, calls onHide method.

As soon as the element is bound, DOM Display Detector directly calls either onShow or onHide according to the element view status. (the second argument isInitial become true in these kinds of calls.)

bindOnce

bindOnce(el: Element | HTMLElement | string, onShow: (el: HTMLElement) => void, onHide?: (el: HTMLElement) => void): void

Unbinds the element automatically once the element is shown on the screen.

When the element is bound to DOM Display Detector, checks if the element is shown on the screen, and if it is, directly calls onShow method and unbinds the element, however, if the element is hidden, calls onHide method and keeps the element bound until it appears on the screen.

unbind

unbind(el: Element | HTMLElement | string): void

Unbinds the given element(s).

License

DOM Display Detector is provided under the MIT License.