Created
May 22, 2018 17:20
-
-
Save mthchz/8eef5c38bc59f920aefa1dcb410cf455 to your computer and use it in GitHub Desktop.
JS element is visible ?
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
/* Element is visible ? | |
*******************************************************************************/ | |
$.fn.isVisible = function(partial) { | |
if( typeof $(this).offset() === 'undefined' ) return false; | |
var $t = $(this), | |
$w = $(window), | |
viewTop = $w.scrollTop(), | |
viewBottom = viewTop + $w.height() - 100, | |
_top = $t.offset().top, | |
_bottom = _top + $t.height(), | |
compareTop = partial === true ? _bottom : _top, | |
compareBottom = partial === true ? _top : _bottom; | |
return ((compareBottom <= viewBottom) && (compareTop >= viewTop)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment