Checking if a tag is on the screen 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 &gt; 0) {
        if (box.left &gt;= window.innerWidth) {
            return false;
        }
    }

    if (box.right &lt;= 0) {
        return false;
    }

    if (box.top &gt; 0) {
        if (box.top &gt;= window.innerHeight) {
            return false;
        }
    }

    if (box.bottom &lt;= 0) {
        return false;
    }

    return true;
}
if (box.left &gt; 0) {
    if (box.left &gt;= window.innerWidth) {
        return false;
    }
}



This seems a little redundant: the innerWidth is going to be greater than 0, so why do you need to conditionals?

Simply remove the outer one.



Your conditions are fairly short. Consider combining them:

if (box.right &lt;= 0 || box.bottom &lt;= 0) {
    return false;
}

if (box.left &gt;= window.innerWidth || box.top &gt;= window.innerHeight) {
    return false;
}




There isn't much more to say about your code, but I have an idea for future improvement: right now, your code will say true even if the element is partially hidden on the screen. How do you plan on handling this?