Created
May 17, 2018 12:21
-
-
Save umkasanki/4fdc261563b284f894c2a51655f54c16 to your computer and use it in GitHub Desktop.
Detecting if an element is in the Viewport : jQuery
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() { | |
var elementTop = $(this).offset().top; | |
var elementBottom = elementTop + $(this).outerHeight(); | |
var viewportTop = $(window).scrollTop(); | |
var 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