Is your document.hidden ?
When you change tabs, videos (for example) do not stop, so slow down your browser.
solution: pause automatically if the element is not visible to the user.
hidden : not visible
visible : display
prerender : download the element offscreen
unloaded : wait the mémory
for do this, you must add an event listener.
the document[hidden] is a minimal configuration, use the -prefixHidden for target browser.
// type, listener, useCapture
document.addEventListener('visibilitychange', hidden, false);
function hidden(){
if(document[hidden]) {
//your action ... (pause your animation or other)
} else {
//your action ... (play ...)
}
}Written by Valentin Beuret
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Js
Authors
Did you know?
JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.
Security insights from Cside
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#