Created
February 23, 2018 16:15
-
-
Save completejavascript/fc271ae5f2681c52c06a970ad3883246 to your computer and use it in GitHub Desktop.
Check whether element is in viewport
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
function isInViewPort(element){ | |
let elementTop = $(element).offset().top; | |
let elementBottom = elementTop + $(element).outerHeight(); | |
let viewPortTop = $(window).scrollTop(); | |
let 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