This function receives an HTMLElement
as an argument and returns true
if the tag is on the screen and false
otherwise.
function isTagVisible(tag) {
var box;
box = tag.getBoundingClientRect();
if (box.left > 0) {
if (box.left >= window.innerWidth) {
return false;
}
}
if (box.right <= 0) {
return false;
}
if (box.top > 0) {
if (box.top >= window.innerHeight) {
return false;
}
}
if (box.bottom <= 0) {
return false;
}
return true;
}