Last active
August 29, 2015 14:23
-
-
Save andreasvirkus/56b47c2658a244b75cc4 to your computer and use it in GitHub Desktop.
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
// Meant to find out if a DOM element is scrolled into view | |
// aka if it is visible on the screen. | |
function appear(elem) { | |
var $elem = $(elem); | |
var $window = $(window); | |
var docViewTop = $window.scrollTop(); | |
var docViewBottom = docViewTop + $window.height(); | |
var elemTop = $elem.offset().top; | |
var elemBottom = elemTop + $elem.height(); | |
return ((elemBottom <= docViewBottom) && (elemTop >= docViewTop)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment