javascript - Run a function constantly -
i'm using excellent inview plugin check if element visible in viewport, using setinterval, function runs once , when element 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 event once, , check separate variable. try this:
var isvisible = false; $('#colorbox').on('inview', function(event, visible) { isvisible = visible; }); var checkviewport = setinterval(function() { if (isvisible) { console.log('yes'); } else { console.log('no'); } }, 5000);
you can structure differently make sure isvisible
isn't global variable , can accessed setinterval
still well.
Comments
Post a Comment