From b43b84496fb65d41c168112987dcc1f631ec11c5 Mon Sep 17 00:00:00 2001 From: danielszanto Date: Thu, 6 Mar 2014 13:34:48 +1100 Subject: [PATCH] Update jquery.visible.js If the element is larger than the window it will register as not visible when edges are off screen. To fix this I added checks if element top is above screen top && element bottom is below screen bottom. The non-native method is rather ugly --- jquery.visible.js | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/jquery.visible.js b/jquery.visible.js index 5cd9aeb..98609fc 100644 --- a/jquery.visible.js +++ b/jquery.visible.js @@ -29,10 +29,12 @@ var rec = t.getBoundingClientRect(), tViz = rec.top >= 0 && rec.top < vpHeight, bViz = rec.bottom > 0 && rec.bottom <= vpHeight, + mVis = rec.top < 0 && rec.bottom > vpHeight, lViz = rec.left >= 0 && rec.left < vpWidth, rViz = rec.right > 0 && rec.right <= vpWidth, - vVisible = partial ? tViz || bViz : tViz && bViz, - hVisible = partial ? lViz || lViz : lViz && rViz; + hmVis= rec.left < 0 && rec.right > vpWidth, + vVisible = partial ? tViz || bViz || mVis : tViz && bViz, + hVisible = partial ? lViz || lViz ||hmVis : lViz && rViz; if(direction === 'both') return clientSize && vVisible && hVisible; @@ -57,12 +59,12 @@ compareRight = partial === true ? _left : _right; if(direction === 'both') - return !!clientSize && ((compareBottom <= viewBottom) && (compareTop >= viewTop)) && ((compareRight <= viewRight) && (compareLeft >= viewLeft)); + return !!clientSize && (((compareBottom <= viewBottom) && (compareTop >= viewTop)) || (partial === true && compareTop > ViewBottom && CompareBottom < viewTop)) && (((compareRight <= viewRight) && (compareLeft >= viewLeft)) || (partial === true && compareLeft > ViewRight && CompareRight < viewLeft)); else if(direction === 'vertical') - return !!clientSize && ((compareBottom <= viewBottom) && (compareTop >= viewTop)); + return !!clientSize && (((compareBottom <= viewBottom) && (compareTop >= viewTop)) || (partial === true && compareTop > ViewBottom && CompareBottom < viewTop)); else if(direction === 'horizontal') - return !!clientSize && ((compareRight <= viewRight) && (compareLeft >= viewLeft)); + return !!clientSize && (((compareRight <= viewRight) && (compareLeft >= viewLeft)) || (partial === true && compareLeft > ViewRight && CompareRight < viewLeft)); } }; -})(jQuery); \ No newline at end of file +})(jQuery);