Just think of having an element in a scrollable parent (the CSS property overflow is set to scroll) and you want to test whether the element is visible or not.
Using this little function you can do the trick:
function isInView(node){
var offsetParent = node.offsetParent;
[...]