There is a page I'm working on. When a user scrolls down to the tabs ("Existing workflow" and "KBCT workflow"), I'd like to change an "Existing workflow" tab to a "KBCT workflow" one with a 5-second delay only. This need to be executed only when the tabs are visible (user scrolled to that position).
Here is the code
tabs = jQuery('#kbct-tabs');
kbctTab = tabs.find('.tab:last-child');
if (tabs.css('visibility') === 'visible') {
setTimeout(function() {
kbctTab.click();
console.log('executed');
}, 5000);
}
And I don't know what's wrong with it, particulary the if statement. It works, but not how it's supposed to. It seems like the browser ignores the if statement and starts to count 5 seconds after the page has loaded, not when a user has scrolled to the tabs. BUT when I write that if statement in the Chrome Console, it works like it's supposed to.
Here is a screenshot.
Can you please tell me what is wrong?