Skip to content

Instantly share code, notes, and snippets.

@marffinn
Last active October 12, 2015 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marffinn/6189e60123ebf8546064 to your computer and use it in GitHub Desktop.
Save marffinn/6189e60123ebf8546064 to your computer and use it in GitHub Desktop.
JavaScript function to check if an DOM element is on screen
$.fn.isOnScreen = function(){
var element = this.get(0);
var bounds = element.getBoundingClientRect();
return bounds.top < window.innerHeight && bounds.bottom > 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment