The following answer to this question works if you remove jQuery cruft (which throws an error if you don't have a jQuery global variable):
[deleted code]
Edit
OP, , , , OP . , . , :
function isVisible(element) {
return isInParents(element) && isInViewport(element);
}
function isInParents(el) {
var rect = el.getBoundingClientRect(),
rectP,
visible = true;
while (el && el.parentNode && el.parentNode.getBoundingClientRect && visible) {
el = el.parentNode;
rectP = el.getBoundingClientRect();
visible = rectInRect(rectP, rect);
}
return visible;
}
function isInViewport (element) {
var rect = element.getBoundingClientRect();
return rectInRect({top:0, left:0,
bottom: window.innerHeight || document.documentElement.clientHeight,
right: window.innerWidth || document.documentElement.clientWidth
}, rect);
}
function rectInRect(r0, r1) {
return r1.top < r0.bottom &&
r1.bottom > r0.top &&
r1.left < r0.right &&
r1.right > r0.left;
}
, , , , - , , .. , , .
, . , .