ifvisible.js
ifvisible.js copied to clipboard
ifvisible.OnEvery doesn't continue after switching tabs
version: 2.0.10
I have the current code
ifvisible.setIdleDuration(900);
ifvisible.idle(function() {
console.log('idle')
document.body.style.opacity = 0.5;
});
ifvisible.wakeup(function() {
console.log('wakeup')
document.body.style.opacity = 1;
});
// instead of setInterval, this will not call the callback if the user is idle
ifvisible.onEvery(5, function() {
console.log('interval');
});
the interval initially gets called correctly, if I switch tabs then get back to the page "wakeup" is fired however the interval doesn't resume
Any fix or workaround for this problem?
@keskistok I rolled back to v1.0.6, seems to work there.
I'm using v1.0.6 and this issue is still happening for me there. I'll likely have to set a timeout on blur and then clear it on focus like this:
ifvisible.on('blur', () => {
let blurredIdleTimeout;
blurredIdleTimeout = setTimeout(() => {
// it's idle, perform actions here
}, MILLISECONDS_TO_IDLE);
});
ifvisible.on('focus', () => {
clearTimeout(blurredIdleTimeout);
});
I fixed this as of 3.0.1 on my fork https://github.com/rosskevin/ifvisible/releases