visibilitychange事件用于监听网页发生变化(进入后台,进入前台)
- 浏览器支持
visibilitychange
是HTML5的API所以支持持最新浏览器 Chrome, Firefox, IE10+ - 用addEventListener添加事件,当页面发生改变就会调用这个函数
const vibchage = 'visibilitychange' || 'webkitvisibilitychange' || 'mozvisibilitychange'
document.addEventListener(vibchage, function () {
});