-
-
Save gartes/53a71b84787d4b253918f0320507a8b9 to your computer and use it in GitHub Desktop.
jQuery viewport checker
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.isInViewport = function() { | |
const elementTop = $(this).offset().top; | |
const elementBottom = elementTop + $(this).outerHeight(); | |
const viewportTop = $(window).scrollTop(); | |
const viewportBottom = viewportTop + $(window).height(); | |
return elementBottom > viewportTop && elementTop < viewportBottom; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment