Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

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().
Source by gist.github.com #
 
PREVIOUS NEXT
Tagged: #javascript #trigger #function #element #viewport
ADD COMMENT
Topic
Name
8+8 =