当前位置:网站首页>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>
边栏推荐
猜你喜欢

Force deduction daily question 540 A single element in an ordered array

JIT deep analysis

Pointer array & array pointer

Continuous assignment of Verilog procedure

C shallow copy and deep copy
![[JVM] detailed description of the process of creating objects](/img/6e/0803b6b63c48337985faae8d5cbe1a.png)
[JVM] detailed description of the process of creating objects
![[golang] leetcode intermediate bracket generation & Full Permutation](/img/93/ca38d97c721ccba2505052ef917788.jpg)
[golang] leetcode intermediate bracket generation & Full Permutation

Form custom verification rules

命名块 verilog

In the era of programmers' introspection, five-year-old programmers are afraid to go out for interviews
随机推荐
Kubernetes cluster storageclass persistent storage resource core concept and use
Kotlin基础学习 17
在QML中加载不同字体
Global and Chinese markets for ultrasonic probe disinfection systems 2022-2028: Research Report on technology, participants, trends, market size and share
Use blocking or non blocking for streamline
Apple added the first iPad with lightning interface to the list of retro products
QT environment generates dump to solve abnormal crash
创业了...
2022 hoisting machinery command examination paper and summary of hoisting machinery command examination
Merge interval, linked list, array
js生成随机数
Docker installs canal and MySQL for simple testing and implementation of redis and MySQL cache consistency
spark调优
[golang] leetcode intermediate bracket generation & Full Permutation
aaaaaaaaaaaaa
ORA-01547、ORA-01194、ORA-01110
Uniapp uses canvas to generate posters and save them locally
PY3, PIP appears when installing the library, warning: ignoring invalid distribution -ip
/silicosis/geo/GSE184854_ scRNA-seq_ mouse_ lung_ ccr2/GSE184854_ RAW/GSM5598265_ matrix_ inflection_ demult
Verilog reg register, vector, integer, real, time register