Answers for "javascript trigger function when element is in viewport"

0

javascript trigger function when element is in viewport

// Determine if an element is in the visible viewport
function isInViewport(element) {
  var rect = element.getBoundingClientRect();
  var html = document.documentElement;
  return (
    rect.top >= 0 &&
    rect.left >= 0 &&
    rect.bottom <= (window.innerHeight || html.clientHeight) &&
    rect.right <= (window.innerWidth || html.clientWidth)
  );
}
// The above function could be used by adding a “scroll” event listener to the window and then calling isInViewport().
Posted by: Guest on May-09-2021

Code answers related to "javascript trigger function when element is in viewport"

Code answers related to "Javascript"

Browse Popular Code Answers by Language