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);
Bind the event once, and check a separate variable. Try this:
You can structure this differently to make sure
isVisible
isn't a global variable and can be accessed by thesetInterval
still as well.