-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.js
72 lines (59 loc) · 1.79 KB
/
helpers.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
;(function($){
$.addLoadEvent = function(func) {
var old = window.onload;
if (typeof window.onload !== 'function') {
window.onload = func;
} else {
window.onload = function() {
if (typeof old === 'function') {
old();
}
func();
};
}
};
$.isJQueryObj = function(elem) {
return typeof jQuery == "function" && elem instanceof jQuery;
};
$.isInViewPort = function(elem) {
var $elem = null,
rect = null;
$w = $(window);
if (elem.nodeType == 1) {
$elem = $(elem);
}
if ($.isJQueryObj(elem)) {
$elem = elem;
}
if ($elem[0].getBoundingClientRect) {
rect = $elem[0].getBoundingClientRect();
return !((rect.bottom < 0) || (rect.top > $w.height()));
}
var topOfElem = $elem.offset().top,
bottomOfElem = $elem.offset().top + $elem.outerHeight(),
scrollTop = $w.scrollTop();
return (scrollTop >= topOfElem && scrollTop < bottomOfElem ) ||
(scrollTop < topOfElem && scrollTop + $w.height() >= bottomOfElem) ||
(scrollTop + $w.height() >= topOfElem && scrollTop + $w.height() < bottomOfElem);
};
$.isFullInViewPort = function(elem) {
var $elem = null,
rect = null;
if (elem.nodeType == 1) {
$elem = $(elem);
}
if ($.isJQueryObj(elem)) {
$elem = elem;
}
if ($elem[0].getBoundingClientRect) {
rect = $elem[0].getBoundingClientRect();
return rect.top >= 0 && rect.bottom <= $(window).height();
} else {
var topOfElem = $elem.offset().top,
bottomOfElem = $elem.offset().top + $elem.outerHeight(),
$w = $(window),
scrollTop = $w.scrollTop();
return (scrollTop <= topOfElem && scrollTop + $w.height() >= bottomOfElem);
}
}
})(jQuery);