I'm using the excellent inView plugin to check if an element is visible in the viewport, using setInterval, but the function only runs once and only when the element IS visible, not otherwise (should run else statement).
var checkViewport = setInterval(function() {
$('#colorbox').on('inview', function(event, visible) {
if (visible) {
console.log('YES');
} else {
console.log('NO');
}
});
}, 5000);