Last active
November 28, 2016 16:37
-
-
Save simonwoo/463c86a65a6119b55464ad702dd0a71a 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
function isElementInViewport (el) { | |
var rect = el.getBoundingClientRect(); | |
return ( | |
rect.top >= 0 && | |
rect.left >= 0 && | |
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */ | |
rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */ | |
); | |
} | |
// JQuery | |
var isElementInViewport = function(check_dom){ | |
var offsetTop = check_dom.offsetTop; | |
return offsetTop >= $(window).scrollTop() && offsetTop< ($(window).scrollTop()+$(window).height()) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment