页面可见性API

Posted on 2015-12-23 23:46  孤弦  阅读(173)  评论(0)    收藏  举报

页面可见性API表示网页是可见的还是不可见的。

 

可见性API有两个属性,一个事件:

document.hiedden:Boolean,表示当前页面是否可见;

document.visibilityState:返回当前页面的可见状态。

  1:“hidden"

  2:”visible“

  3:”prerender"

  4: "preview" 预览

事件:

  visibilitychange:当可见状态改变时候触发的事件

 

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title></title>
</head>
<body>
<script type="text/javascript">
document.addEventListener('visibilitychange',function(){
document.title = document.hidden ? '你好丑' :'你好帅'
})

</script>
</body>
</html>

博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3