-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery.onscreen.js
29 lines (29 loc) · 947 Bytes
/
jquery.onscreen.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
;(function($) {
var win = $(window);
function check(el) {
el = $(el);
if (!el.is(':visible')) {
return false;
}
var viewport = {
top : win.scrollTop(),// + 15,
left : win.scrollLeft()
};
viewport.right = viewport.left + win.width();
viewport.bottom = viewport.top + win.height();
var bounds = el.offset();
bounds.right = bounds.left + el.outerWidth();
bounds.bottom = bounds.top + el.outerHeight();// - 15;
if (!(viewport.right < bounds.left || viewport.left > bounds.right || viewport.bottom < bounds.top || viewport.top > bounds.bottom)) {
return true;
} else {
return false;
}
}
$.expr[':']['onscreen'] = function(el) {
return check($(el));
}
$.expr[':']['notonscreen'] = function(el) {
return !check($(el));
}
})(jQuery);