当前位置:网站首页>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>
边栏推荐
- 终日乾乾,夕惕若厉
- What is the binding path of SAP ui5
- GSE104154_scRNA-seq_fibrotic MC_bleomycin/normalized AM3
- Global and Chinese markets for infant care equipment, 2022-2028: Research Report on technology, participants, trends, market size and share
- Design details of SAP e-commerce cloud footernavigationcomponent
- 创业了...
- Kotlin基础学习 16
- PY3 link MySQL
- [JS reverse series] analysis of a customs publicity platform
- Global and Chinese markets for welding equipment and consumables 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢
QT environment generates dump to solve abnormal crash
PY3, PIP appears when installing the library, warning: ignoring invalid distribution -ip
Design details of SAP e-commerce cloud footernavigationcomponent
This article describes the step-by-step process of starting the NFT platform project
Screenshot literacy tool download and use
Getting started with MQ
MySQL advanced (Advanced) SQL statement (II)
Kubernetes cluster storageclass persistent storage resource core concept and use
SAML2.0 笔记(一)
Analyse de 43 cas de réseaux neuronaux MATLAB: Chapitre 42 opérations parallèles et réseaux neuronaux - - opérations parallèles de réseaux neuronaux basées sur CPU / GPU
随机推荐
MSI announced that its motherboard products will cancel all paper accessories
Kotlin基础学习 15
Download and use of the super perfect screenshot tool snipaste
ThreadLocal详解
Uniapp uses canvas to generate posters and save them locally
JDBC details
只需简单几步 - 开始玩耍微信小程序
终日乾乾,夕惕若厉
Docker安装canal、mysql进行简单测试与实现redis和mysql缓存一致性
MySQL connection query and subquery
Kotlin基础学习 17
Verilog reg register, vector, integer, real, time register
Gradle 笔记
Pycharm2021 delete the package warehouse list you added
Verilog 时序控制
Delphi xe10.4 installing alphacontrols15.12
[JVM] detailed description of the process of creating objects
Verilog parallel block implementation
Go execute shell command
Custom classloader that breaks parental delegation