Get the App
SLTechnology News&Howtos  ›  Servers  › 

How to use _ window.onfocus and _ window.onblur to achieve window focus

Shulou Source: shulou.com Published: 2022-05-31 19:56:32 10月04日 Update

How to use_window.onfocus and_window.onblur to achieve window focus, for this problem, this article describes the corresponding analysis and solution in detail, hoping to help more friends who want to solve this problem find a simpler and easier way.

current window gets focus js event, html5 before release we used_window.onfocus and_window.onblur to get window focus and lose window focus,

Listen for onfocus() and_window.onblur() event implementation//current window gets focus

_window.onfocus = function() {

//Play animation or video

};

//The current window loses focus

_window.onblur = function() {

//pause animation or video

};

This method can switch labels to pause animation video, but it will bring a problem, because it is to determine the focus, if it is on the current page spread a small window, then the current page will pause animation, imagine, if you watch movies, while opening a chat window and MM chat, when you operate the chat window, video pause, this is not the effect you want.

Now let's see how HTML5 works. H5 provides many simple and useful APIs, and the Page Visibility API is one of them. The Page Visibility API helps us make this determination.

About how to use_window.onfocus and_window.onblur to achieve the window focus problem solution shared here, I hope the above content can be of some help to everyone, if you still have a lot of doubts not solved, you can pay attention to the industry information channel to learn more related knowledge.

Tags: Focus animation video questions help events methods more pages answers practical easy effective easy upper bunk content guys buddies that is effects Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux vpn NVidia MySQL Shulou Tech Info