New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@cevad-tokatli/dom-display-detector

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@cevad-tokatli/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.

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-77.78%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

FAQs

Package last updated on 14 Feb 2023

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