Created
May 14, 2018 13:49
-
-
Save Dexdot/d18b7aab626b0e31058622c34a616c05 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