Created
March 23, 2018 11:59
-
-
Save khripunovpp/7a29dc9db8e6c8ad322f073206dbd985 to your computer and use it in GitHub Desktop.
isOnScreen
This file contains hidden or 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(shift){ | |
if(!shift){ | |
shift = 0; | |
} | |
var viewport = {}; | |
viewport.top = $(window).scrollTop(); | |
viewport.bottom = viewport.top + $(window).height(); | |
var bounds = {}; | |
bounds.top = this.offset().top + shift; | |
bounds.bottom = bounds.top + this.outerHeight() - shift; | |
return ((bounds.top <= viewport.bottom) && (bounds.bottom >= viewport.top)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment