I am developing a small game in js/jquery and I am looking for an event allowing to pause the function and timer when the player is not on the window or leave the window, do you know this event, I could not find it.
Thank you.
I am developing a small game in js/jquery and I am looking for an event allowing to pause the function and timer when the player is not on the window or leave the window, do you know this event, I could not find it.
Thank you.
You're looking for the blur
and focus
events.
addEventListener('blur', function(){
console.log('Window no longer active');
});
addEventListener('focus', function(){
console.log('Window is now active');
});