Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional check for horizontal scroll compatability #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
50 changes: 34 additions & 16 deletions jquery.onscreen.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
// onScreen jQuery plugin v0.2.1
// onScreen jQuery plugin v0.2.2
// (c) 2011 Ben Pickles
//
// http://benpickles.github.com/onScreen
//
// Released under MIT license.
;(function($) {
$.expr[":"].onScreen = function(elem) {
var $window = $(window)
var viewport_top = $window.scrollTop()
var viewport_height = $window.height()
var viewport_bottom = viewport_top + viewport_height
var $elem = $(elem)
var top = $elem.offset().top
var height = $elem.height()
var bottom = top + height
(function($) {
$.expr[":"].onScreen = function(elem) {
var $window = $(window);
var viewport_top = $window.scrollTop();
var viewport_left = $window.scrollLeft();
var viewport_width = $window.width();
var viewport_height = $window.height();
var viewport_right = viewport_left + viewport_width;
var viewport_bottom = viewport_top + viewport_height;
var $elem = $(elem);
var top = $elem.offset().top;
var left = $elem.offset().left;
var width = $elem.width();
var height = $elem.height();
var right = left + width;
var bottom = top + height;

return (top >= viewport_top && top < viewport_bottom) ||
(bottom > viewport_top && bottom <= viewport_bottom) ||
(height > viewport_height && top <= viewport_top && bottom >= viewport_bottom)
}
})(jQuery);
var onScreen = (
(
(left >= viewport_left && left < viewport_right) ||
(right > viewport_left && right <= viewport_right) ||
(width > viewport_width && left <= viewport_left && right >= viewport_right)
)
&&
(
(top >= viewport_top && top < viewport_bottom) ||
(bottom > viewport_top && bottom <= viewport_bottom) ||
(height > viewport_height && top <= viewport_top && bottom >= viewport_bottom)
)
);

return onScreen;
};
})(jQuery);
4 changes: 2 additions & 2 deletions jquery.onscreen.min.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// onScreen jQuery plugin v0.2.1
// onScreen jQuery plugin v0.2.2
// (c) 2011 Ben Pickles
//
// http://benpickles.github.com/onScreen
//
// Released under MIT license.
(function(a){a.expr[":"].onScreen=function(b){var c=a(window),d=c.scrollTop(),e=c.height(),f=d+e,g=a(b),h=g.offset().top,i=g.height(),j=h+i;return h>=d&&h<f||j>d&&j<=f||i>e&&h<=d&&j>=f}})(jQuery);
(function(e){e.expr[":"].onScreen=function(t){var n=e(window);var r=n.scrollTop();var i=n.scrollLeft();var s=n.width();var o=n.height();var u=i+s;var a=r+o;var f=e(t);var l=f.offset().top;var c=f.offset().left;var h=f.width();var p=f.height();var d=c+h;var v=l+p;var m=(c>=i&&c<u||d>i&&d<=u||h>s&&c<=i&&d>=u)&&(l>=r&&l<a||v>r&&v<=a||p>o&&l<=r&&v>=a);return m}})(jQuery)