Answers for "js check if element is 90% in viewport"

3

how to check element is in viewport

function isVisible (ele) {
  const { top, bottom } = ele.getBoundingClientRect();
  const vHeight = (window.innerHeight || document.documentElement.clientHeight);

  return (
    (top > 0 || bottom > 0) &&
    top < vHeight
  );
}
Posted by: Guest on December-25-2020
2

how to check if element is in viewport

function isInViewport(element) {
    const rect = element.getBoundingClientRect();
    return (
        rect.top >= 0 &&
        rect.left >= 0 &&
        rect.bottom <= ((window.innerHeight + rect.height) || document.documentElement.clientHeight) &&
        rect.right <= (window.innerWidth || document.documentElement.clientWidth)
    );
}

//optimized from the stackOverflow answer to account 
//for element heights and widths (in vertical/horizontal scrolling)
Posted by: Guest on October-26-2021

Code answers related to "js check if element is 90% in viewport"

Code answers related to "Javascript"

Browse Popular Code Answers by Language