Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 19 additions & 6 deletions jquery.visible.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* only accounts for vertical position, not horizontal.
*/
var $w = $(window);
$.fn.visible = function(partial,hidden,direction){
$.fn.visible = function(partial,hidden,direction,pv){

if (this.length < 1)
return;
Expand All @@ -21,16 +21,24 @@
vpWidth = $w.width(),
vpHeight = $w.height(),
direction = (direction) ? direction : 'both',
clientSize = hidden === true ? t.offsetWidth * t.offsetHeight : true;
clientSize = hidden === true ? t.offsetWidth * t.offsetHeight : true,
pvh = 0,
pvw = 0;

if (pv > 0) {
pvh = $t.height()*pv/100;
pvw = $t.width()*pv/100;
}


if (typeof t.getBoundingClientRect === 'function'){

// Use this native browser method, if available.
var rec = t.getBoundingClientRect(),
tViz = rec.top >= 0 && rec.top < vpHeight,
bViz = rec.bottom > 0 && rec.bottom <= vpHeight,
lViz = rec.left >= 0 && rec.left < vpWidth,
rViz = rec.right > 0 && rec.right <= vpWidth,
tViz = (rec.top + pvh) >= 0 && (rec.top + pvh) < vpHeight,
bViz = (rec.bottom - pvh) > 0 && (rec.bottom - pvh) <= vpHeight,
lViz = (rec.left + pvw) >= 0 && (rec.left + pvw) < vpWidth,
rViz = (rec.right - pvw) > 0 && (rec.right - pvw) <= vpWidth,
vVisible = partial ? tViz || bViz : tViz && bViz,
hVisible = partial ? lViz || rViz : lViz && rViz;

Expand All @@ -56,6 +64,11 @@
compareLeft = partial === true ? _right : _left,
compareRight = partial === true ? _left : _right;

compareTop = compareTop + pvh;
compareBottom = compareBottom - pvh;
compareRight = compareRight - pvw;
compareLeft = compareLeft + pvw;

if(direction === 'both')
return !!clientSize && ((compareBottom <= viewBottom) && (compareTop >= viewTop)) && ((compareRight <= viewRight) && (compareLeft >= viewLeft));
else if(direction === 'vertical')
Expand Down