Jquery实现前端窗口得全屏/退出全屏得切换

通过JQ实现前端页面全屏、退出全屏得切换。当在全屏状态下,显示退出全屏菜单,非全屏状态下,显示全屏菜单。
原文链接:https://www.liyinbing.cn/article/det/58

1、html部分

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>全屏——退出全屏</title>
    <style>
        body {
            background-color: black;
        }

        .fullScreen {
            position: absolute;
            top: 20px;
            right: 30px;
        }

        .exitFullScreen {
            display: none;
            position: absolute;
            top: 20px;
            right: 30px;
        }

        .main {
            color: orangered;
            font-size: 60px;
            margin: 150px auto;
            text-align: center;
        }
    </style>
</head>
<body>
<button class="fullScreen">全屏</button>
<button class="exitFullScreen">退出全屏</button>
<div class="main">我现在非全屏状态</div>

<script src="./jquery-2.1.1.min.js"></script>
<script src="./script.js"></script>
</body>
</html>

2、JS代码

function handleFullScreen() {
    var de = document.documentElement;
    if (de.requestFullscreen) {
        de.requestFullscreen();
    } else if (de.msRequestFullscreen) {
        de.msRequestFullscreen();
    } else if (de.webkitRequestFullScreen) {
        de.webkitRequestFullScreen();
    } else if (de.mozRequestFullScreen) {
        de.mozRequestFullScreen();
    } else {
        wtx.info("当前浏览器不支持全屏!");
    }
}

function exitFullscreen() {
    var de = document;
    if (de.exitFullscreen) {
        de.exitFullscreen();
    } else if (de.msExitFullscreen) {
        de.msExitFullscreen();
    } else if (de.mozCancelFullScreen) {
        de.mozCancelFullScreen();
    } else if (de.webkitExitFullscreen) {
        de.webkitExitFullscreen();
    }
}

$(function () {
    let body = $("body");
    let main = $(".main")
    let fullScreenButton = $("button.fullScreen");
    let exitFullScreenButton = $("button.exitFullScreen");
    body.on("click", "button.fullScreen", function () {
        handleFullScreen();
    })

    body.on("click", "button.exitFullScreen", function () {
        exitFullscreen();
    })

    $(document).on("fullscreenchange", function (event) {
        if (document.fullscreenElement || document.webkitFullscreenElement) {
            fullScreenButton.css('display', 'none');
            exitFullScreenButton.css("display", "inline-block");
            main.text("我现在是全屏状态");
        } else {
            fullScreenButton.css('display', 'inline-block');
            exitFullScreenButton.css("display", "none");
            main.text("我现在非全屏状态");
        }
    })
})

3、实现效果
非全屏状态

换个行===================================>

全屏状态
代码链接:https://gitee.com/Bingo11/my-projects/tree/63c4f545cc3f3504564b3bcb45b45bc5bc2ee061/Web/jq%E5%AE%9E%E7%8E%B0%E5%85%A8%E5%B1%8F___%E9%80%80%E5%87%BA%E5%85%A8%E5%B1%8F

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
要使用jQuery实现前端Excel导入导出,需要使用以下步骤: 1. 导入jQuery库和jQuery插件,如TableExport插件。 2. 在HTML页面中创建一个表格。 3. 使用jQuery将Excel数据导入到表格中。 4. 使用jQuery将表格数据导出为Excel文件。 以下是一个基本的示例代码: HTML代码: ``` <table id="mytable"> <thead> <tr> <th>Name</th> <th>Age</th> <th>Gender</th> </tr> </thead> <tbody> <tr> <td>John</td> <td>30</td> <td>Male</td> </tr> <tr> <td>Jane</td> <td>25</td> <td>Female</td> </tr> </tbody> </table> <button id="export-btn">Export to Excel</button> <input type="file" id="import-file"> <button id="import-btn">Import from Excel</button> ``` JavaScript代码: ``` // 导出Excel文件 $("#export-btn").click(function(){ $("#mytable").tableExport({ type:'excel', fileName: 'mytable' }); }); // 导入Excel文件 $("#import-btn").click(function(){ let file = $("#import-file").prop('files')[0]; let reader = new FileReader(); reader.onload = function(e){ let data = e.target.result; let workbook = XLSX.read(data, {type: 'binary'}); let sheet_name = workbook.SheetNames[0]; let worksheet = workbook.Sheets[sheet_name]; let table = XLSX.utils.sheet_to_json(worksheet, {header:1}); // 将Excel数据导入到表格中 $("#mytable tbody").empty(); for(let i=1; i<table.length; i++){ let row = "<tr>"; row += "<td>" + table[i][0] + "</td>"; row += "<td>" + table[i][1] + "</td>"; row += "<td>" + table[i][2] + "</td>"; row += "</tr>"; $("#mytable tbody").append(row); } }; reader.readAsBinaryString(file); }); ``` 上述代码使用了TableExport插件和XLSX.js库来实现前端Excel导入导出功能。其中,TableExport插件用于将表格数据导出为Excel文件,XLSX.js库用于将Excel文件数据导入到表格中。注意,XLSX.js库需要在代码中导入。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

八戒无戒i

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值