JAVASCRIPT - HOW TO Check if Element is in Screen - Javascript Source Code

JAVASCRIPT - HOW TO Check if an HTML Element is Visible in the Website Visitors Screen or Viewport with a Simple Function [isInViewport]

Home Short:

We can determine if an html element is visible within the website visitors screen or viewport with a very simple function that gets the left, top, right and bottom rectangle edge of the element and checks to see if any part of that element is within the viewable area of the screen. This is what the website visitor sees in their web browser.

To use this function just pass it the element in question. The function will return TRUE if any part of the element in question IS within the website visitors view and the function will return FALSE if the element is NOT within the website visitors viewport.

How to Detect WHEN Element Comes into View

To montior and detect when an element DOES come into view you can either set a timer with the Javascript function setInterval, setting an interval of perhaps a second or so, depending on how quickly you need to be alerted to when the element comes into view, or use window.onscroll

S
H
A
R
E