当前位置:网站首页>The page in H5 shows hidden execution events
The page in H5 shows hidden execution events
2022-07-02 03:24:00 【seventy-five million six hundred and twenty-four thousand eight】
visibilitychange event
Is the browser's new event method , It is mainly used to monitor whether the page is displayed , Now mainstream browsers support this event , When the browser switches tabs , To minimize the , This event will be triggered automatically during maximization and other operations .
document.hidden attribute
Used to indicate whether the current page is hidden or active display , When the page is hidden and inactive, the value is true, When the page is active, the value is false, The property is read-only .
We can pass the above visibilitychange Event combination document.hidden Do some effect
A page with background music :
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title> test document.hidden</title>
</head>
<body>
<!-- Create a player -->
<audio id="audioDom" src="https://aimg8.oss-cn-shanghai.aliyuncs.com/VUEAdmin/gameActivity/DaZhuanPan/back_music.mp3"></audio>
<!-- A play button -->
<button id="btn"> Play </button>
<script> // Get... On the page audio player Dom Elements var audioDom = document.getElementById('audioDom'); // Bind the event to the button and play the music when it is clicked document.getElementById('btn').addEventListener('click', function(){
audioDom.play(); }); // to document Bind one visibilitychange event , This event is executed when the current page is displayed or hidden document.addEventListener("visibilitychange", function() {
// Judge the present document Whether to show or hide if(!document.hidden){
// If it is in the display state, perform the music playing operation audioDom.play(); }else{
// If it is hidden, perform music pause audioDom.pause(); } }); </script>
</body>
</html>
边栏推荐
- PY3, PIP appears when installing the library, warning: ignoring invalid distribution -ip
- venn圖取交集
- Common means of modeling: aggregation
- Go execute shell command
- aaaaaaaaaaaaa
- Review materials of project management PMP high frequency examination sites (8-1)
- Gradle 笔记
- Knowing things by learning | self supervised learning helps improve the effect of content risk control
- ORA-01547、ORA-01194、ORA-01110
- Start a business
猜你喜欢
Retrofit's callback hell is really vulnerable in kotlin synergy mode
Download and use of the super perfect screenshot tool snipaste
[JS reverse series] analysis of a customs publicity platform
GB/T-2423. XX environmental test documents, including the latest documents
MySQL connection query and subquery
[HCIA continuous update] working principle of OSPF Protocol
Framing in data transmission
Exchange rate query interface
This article describes the step-by-step process of starting the NFT platform project
JIT deep analysis
随机推荐
[HCIA continuous update] overview of dynamic routing protocol
One of the future trends of SAP ui5: embrace typescript
数据传输中的成帧
C # joint halcon out of halcon Environment and various Error Reporting and Resolution Experiences
Comment élaborer une stratégie nuageuse à l'ère des nuages mixtes
Eight steps of agile development process
流线线使用阻塞还是非阻塞
Gradle notes
[数据库]JDBC
Gradle 笔记
Spark Tuning
Design details of SAP e-commerce cloud footernavigationcomponent
In depth analysis of C language - variable error prone knowledge points # dry goods inventory #
js生成随机数
Verilog state machine
venn圖取交集
4. Find the median of two positive arrays
Verilog timing control
ZABBIX API creates hosts in batches according to the host information in Excel files
[C Advanced] brother Peng takes you to play with strings and memory functions