js元素全屏和退出全屏效果

admin發表於2017-04-14

本章節分享一段程式碼例項,它實現了元素控制元素全屏和退出全屏的功能。

程式碼例項如下:

[HTML] 純文字檢視 複製程式碼
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="author" content="http://www.softwhy.com/" />
<title>螞蟻部落</title>
<style>
.container {
  width: 50%;
  height: 300px;
  margin: 50px auto;
}
#full {
  width: 100%;
  height: 100%;
  position: relative;
  background-color: #1a85ba;
  background: linear-gradient(to bottom right, #00a5a5, #3366cc);
  color: #fff;
  font-size: 36px;
  text-align: center;
  line-height: 200px;
}
#btn {
  position: absolute;
  top: 20px;
  right: 20px;
  width: 40px;
  font-size: 16px;
  height: 24px;
  line-height: 24px;
  text-align: center;
  cursor: pointer;
  background-color: green;
}
#btn.active {
  background-color: red;
}
</style>
<script src="demo/js/js/fullscreen.js"></script>
<script>
window.onload=function(){
  var full=new fullscreen({
    btnClass:"active",
    element:document.getElementById("full"),
    fullscreenBtn:document.getElementById("btn")
  })
}
</script>
</head>
<body>
<div class="container">
  <div id="full">
    螞蟻部落
    <div id="btn">全屏</div>
  </div>
</div>
</body>
</html>

相關文章