Skip to content

Instantly share code, notes, and snippets.

@rabarbara
Created November 3, 2017 09:24
Show Gist options
  • Save rabarbara/8ff849d40a55bdfe24b4d68d942fa62e to your computer and use it in GitHub Desktop.
Save rabarbara/8ff849d40a55bdfe24b4d68d942fa62e to your computer and use it in GitHub Desktop.
Did the element scroll into view?
//https://stackoverflow.com/a/22480938/5400353
function isScrolledIntoView(el) {
var elemTop = el.getBoundingClientRect().top;
var elemBottom = el.getBoundingClientRect().bottom;
// Only completely visible elements return true:
//var isVisible = (elemTop >= 0) && (elemBottom <= window.innerHeight);
// Partially visible elements return true:
isVisible = elemTop < window.innerHeight && elemBottom >= 0;
return isVisible;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment