
Security News
TypeScript is Porting Its Compiler to Go for 10x Faster Builds
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
@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.
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
TypeScript is porting its compiler to Go, delivering 10x faster builds, lower memory usage, and improved editor performance for a smoother developer experience.
Research
Security News
The Socket Research Team has discovered six new malicious npm packages linked to North Korea’s Lazarus Group, designed to steal credentials and deploy backdoors.
Security News
Socket CEO Feross Aboukhadijeh discusses the open web, open source security, and how Socket tackles software supply chain attacks on The Pair Program podcast.