Last Updated: February 25, 2016
·
1.218K
· beuretv

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 ...)
}

}

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Related Tags
#js
#javascript
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