Created
May 4, 2020 14:59
-
-
Save Farmatique/0e131b434141fe7d4d9e9c871393000d to your computer and use it in GitHub Desktop.
Check if element in viewport (even NOT FULL element, but partially)
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
function isScrolledIntoView(elem){ | |
var docViewTop = $(window).scrollTop(); | |
var docViewBottom = docViewTop + $(window).height(); | |
var elemTop = $(elem).offset().top; | |
var elemBottom = elemTop + $(elem).height(); | |
return Math.min(elemBottom, docViewBottom) >= Math.max(elemTop, docViewTop); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment