效果图:单击按钮切换全屏效果
全部代码:
<!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>全屏效果</title>
<style>
.wrap{
display: flex;
justify-content: flex-end;
padding: 30px;
}
.box{
display: flex;
flex-direction: column;
justify-content: space-between;
width: 50px;
height: 50px;
}
.bb_box{
display: flex;
justify-content: space-between;
width: inherit;
height: 30%;
}
.bb{
width: 30%;
border-style: solid;
border-color: cornflowerblue;
box-sizing: border-box;
}
.b1{
border-width: 5px 0 0 5px;
}
.b2{
border-width: 5px 5px 0 0;
}
.b3{
border-width: 0 0 5px 5px;
}
.b4{
border-width: 0 5px 5px 0;
}
</style>
</head>
<body>
<div class="wrap">
<div class="box" onclick="toggleFullScreen();">
<div class="bb_box">
<div class="bb b1"></div>
<div class="bb b2"></div>
</div>
<div class="bb_box">
<div class="bb b3"></div>
<div class="bb b4"></div>
</div>
</div>
</div>
<script>
let bbs = document.getElementsByClassName('bb');
let bbs_arr = ['bb b1','bb b2','bb b3','bb b4'];
function toggleFullScreen() {
if (!document.fullscreenElement && !document.mozFullScreenElement && !document.webkitFullscreenElement) {
if (document.documentElement.requestFullscreen) {
document.documentElement.requestFullscreen();
} else if (document.documentElement.mozRequestFullScreen) {
document.documentElement.mozRequestFullScreen();
} else if (document.documentElement.webkitRequestFullscreen) {
document.documentElement.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT);
}
for(let i = 0;i<bbs.length;i++){
bbs[i].className = bbs_arr[3-i];
}
}else {
if (document.cancelFullScreen) {
document.cancelFullScreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitCancelFullScreen) {
document.webkitCancelFullScreen();
}
for(let i = 0;i<bbs.length;i++){
bbs[i].className = bbs_arr[i]
}
}
}
</script>
</body>
</html>