forked from customd/jquery-visible
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
45 additions
and
35 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,41 @@ | ||
(function($){ | ||
|
||
/** | ||
* Copyright 2012, Digital Fusion | ||
* Licensed under the MIT license. | ||
* http://teamdf.com/jquery-plugins/license/ | ||
* | ||
* @author Sam Sehnert | ||
* @desc A small plugin that checks whether elements are within | ||
* the user visible viewport of a web browser. | ||
* only accounts for vertical position, not horizontal. | ||
*/ | ||
$.fn.visible = function(partial,hidden){ | ||
|
||
var $t = $(this).eq(0), | ||
t = $t.get(0), | ||
$w = $(window), | ||
viewTop = $w.scrollTop(), | ||
viewBottom = viewTop + $w.height(), | ||
_top = $t.offset().top, | ||
_bottom = _top + $t.height(), | ||
compareTop = partial === true ? _bottom : _top, | ||
compareBottom = partial === true ? _top : _bottom, | ||
clientSize = hidden === true ? t.offsetWidth * t.offsetHeight : true; | ||
|
||
return !!clientSize && ((compareBottom <= viewBottom) && (compareTop >= viewTop)); | ||
/** | ||
* Copyright 2012, Digital Fusion | ||
* Licensed under the MIT license. | ||
* http://teamdf.com/jquery-plugins/license/ | ||
* | ||
* @author Sam Sehnert | ||
* @desc A small plugin that checks whether elements are within | ||
* the user visible viewport of a web browser. | ||
* only accounts for vertical position, not horizontal. | ||
*/ | ||
$.fn.visible = function(partial,hidden,direction){ | ||
|
||
var $t = $(this).eq(0), | ||
t = $t.get(0), | ||
$w = $(window), | ||
viewTop = $w.scrollTop(), | ||
viewBottom = viewTop + $w.height(), | ||
viewLeft = $w.scrollLeft(), | ||
viewRight = viewLeft + $w.width(), | ||
_top = $t.offset().top, | ||
_bottom = _top + $t.height(), | ||
_left = $t.offset().left, | ||
_right = _left + $t.width(), | ||
compareTop = partial === true ? _bottom : _top, | ||
compareBottom = partial === true ? _top : _bottom, | ||
compareLeft = partial === true ? _right : _left, | ||
compareRight = partial === true ? _left : _right, | ||
clientSize = hidden === true ? t.offsetWidth * t.offsetHeight : true, | ||
direction = (direction) ? direction : 'both'; | ||
|
||
if(direction === 'both') | ||
return !!clientSize && ((compareBottom <= viewBottom) && (compareTop >= viewTop)) && ((compareRight <= viewRight) && (compareLeft >= viewLeft)); | ||
else if(direction === 'vertical') | ||
return !!clientSize && ((compareBottom <= viewBottom) && (compareTop >= viewTop)); | ||
else if(direction === 'horizontal') | ||
return !!clientSize && ((compareRight <= viewRight) && (compareLeft >= viewLeft)); | ||
}; | ||
|
||
})(jQuery); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.