Last active
October 12, 2015 12:20
-
-
Save marffinn/6189e60123ebf8546064 to your computer and use it in GitHub Desktop.
JavaScript function to check if an DOM element is on screen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.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