【HTML前端全屏效果——按钮切换】

效果图:单击按钮切换全屏效果

 

 全部代码:

<!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>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值