DOM Element Detector Is Visible Using jQuery

DOM-element-detector is a very small script for jQuery that calculates an element’s position from the top of the page and then performs custom functions when the element becomes visible/invisible on scroll.

jquery check if element is visible on screen, check if element is display none jquery, jquery check if element is visible in scroll div, javascript check if element is visible on screen

How to make use of it:

1. Load the mandatory jQuery library within the doc.

<script src="/path/to/cdn/jquery.slim.min.js"></script>

2. The major function to detect if a component is visible/invisible.

let scrollTop = $(this).scrollTop();
function domElemDetector(el) {
  if ($(el).length) {
    let elemOffsetTop = el.offset().top
    let elemHeight = el.outerHeight();
    let windowHeight = $(window).outerHeight();
    if (scrollTop >= (elemOffsetTop - (windowHeight / 2))) {
      // do some cool stuff when the element is visible
    } else {
      // do some cool stuff when the element is invisible
    }
  }
}

3. Apply the DOM Element Detector to your component.

<div class="element">
  ...
</div>
domElemDetector($('.element'));

4. Enable the DOM Element Detector on the web page scroll.

$(document).ready(function () {
  $(function () {
    $(window).on('scroll', function () {
      let scrollTop = $(this).scrollTop();
      function domElemDetector(el) {
        if ($(el).length) {
          let elemOffsetTop = el.offset().top
          let elemHeight = el.outerHeight();
          let windowHeight = $(window).outerHeight();
          if (scrollTop >= (elemOffsetTop - (windowHeight / 2))) {
            // do some cool stuff when the element is visible
          } else {
            // do some cool stuff when the element is invisible
          }
        }
      }
      domElemDetector($('.element'));
    });
  });
});

Check Whether A DOM Element, DOM-element-detector Plugin/Github, jquery check if element exists, jquery visibility hidden


See Demo And Download

Official Website(kawsarBinSiraj): Click Here

This superior jQuery/javascript plugin is developed by kawsarBinSiraj. For extra Advanced Usages, please go to the official website.

Related Posts

Bootstrap-Notification-Message-Alert-Plugin

Bootstrap Notification Message Alert Plugin with jQuery

BootstrapMsg is a jQuery plugin for displaying messages with Bootstrap alert classes to generate hierarchical in-page navigation for an extended webpage sectioned by heading components. Using Bootstrap…

jquery-google-chart-plugin

jQuery Plugin for Transforming HTML Tables Into Charts Using Google Charts

Chartinator is a jQuery plugin for converting HTML tables, Google Sheets and js arrays into charts using Google Charts. Use data from HTML tables Chartinator is designed…

free-vue-chart-library

Customizable & Composable Charts for VueJS | vue-wcharts

WCharts is a library that makes it easy to create your own charts using Vuejs. You can easily create reusable chart components. Use a basic layout or…

javascript-emoji-gif-picker-library

A Modern GIF | Emoji Picker Vue3 Components For Your App

vue3 discord picker is a new emoji/gif picker for your app! based on disagreement. This component is only available in vue3. Reworking the Print and Configuration API….

neon-button-css

Animated Neon Light Buttons Animation Effects In Pure CSS

Animated Neon Buttons is a set of neon buttons with animated reflections and borders, written in pure CSS/CSS3. Must Read: Simple Superb Animations Particle Effect Buttons For…

smooth-zoom-images

A Lightweight Javascript Library For Zooming / Enlarging Images | Zoom.js

Smooth Zoom is a lightweight javascript library for enlarging images like Medium, and Google Photos, which displays images at a large size just like you saw it…