Skip to content

Instantly share code, notes, and snippets.

@yashsharma04
Created August 28, 2020 08:26
Show Gist options
  • Save yashsharma04/27283d83def285af902b94cfbbad75d6 to your computer and use it in GitHub Desktop.
Save yashsharma04/27283d83def285af902b94cfbbad75d6 to your computer and use it in GitHub Desktop.
function isInViewport(element) {
const rect = element.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom - 62 <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment