![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
@cevad-tokatli/dom-display-detector
Advanced tools
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.
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.
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
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')
})
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(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(el: Element | HTMLElement | string): void
Unbinds the given element(s).
DOM Display Detector is provided under the MIT License.
FAQs
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.
The npm package @cevad-tokatli/dom-display-detector receives a total of 1 weekly downloads. As such, @cevad-tokatli/dom-display-detector popularity was classified as not popular.
We found that @cevad-tokatli/dom-display-detector demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.