vue 支持部分全屏 支持点击ecs 关闭全屏

<template>

<div>

<div id="screen" @click="screen">Toggle Fullscreen</div>

</div>

</template>

<script>

export default {

data() {

return {

fullscreen: false

};

},

mounted() {

document.addEventListener('fullscreenchange', this.handleFullScreenChange);

document.addEventListener('keydown', this.handleKeyDown);

},

beforeDestroy() {

document.removeEventListener('fullscreenchange', this.handleFullScreenChange);

document.removeEventListener('keydown', this.handleKeyDown);

},

methods: {

handleFullScreenChange() {

if (!document.fullscreenElement) {

this.fullscreen = false;

}

},

handleKeyDown(event) {

if (event.key === 'Escape') {

if (this.fullscreen) {

this.exitFullScreen();

}

}

},

screen() {

let element = document.getElementById('screen');

if (this.fullscreen) {

this.exitFullScreen();

} else {

this.enterFullScreen(element);

}

this.fullscreen = !this.fullscreen;

},

enterFullScreen(element) {

if (element.requestFullscreen) {

element.requestFullscreen();

} else if (element.webkitRequestFullScreen) {

element.webkitRequestFullScreen();

} else if (element.mozRequestFullScreen) {

element.mozRequestFullScreen();

} else if (element.msRequestFullscreen) {

element.msRequestFullscreen();

}

},

exitFullScreen() {

if (document.exitFullscreen) {

document.exitFullscreen();

} else if (document.webkitCancelFullScreen) {

document.webkitCancelFullScreen();

} else if (document.mozCancelFullScreen) {

document.mozCancelFullScreen();

} else if (document.msExitFullscreen) {

document.msExitFullscreen();

}

}

}

};

</script>

相关推荐
hackeroink38 分钟前
【2024版】最新推荐好用的XSS漏洞扫描利用工具_xss扫描工具
前端·xss
迷雾漫步者2 小时前
Flutter组件————FloatingActionButton
前端·flutter·dart
向前看-3 小时前
验证码机制
前端·后端
燃先生._.4 小时前
Day-03 Vue(生命周期、生命周期钩子八个函数、工程化开发和脚手架、组件化开发、根组件、局部注册和全局注册的步骤)
前端·javascript·vue.js
高山我梦口香糖5 小时前
[react]searchParams转普通对象
开发语言·前端·javascript
m0_748235245 小时前
前端实现获取后端返回的文件流并下载
前端·状态模式
m0_748240256 小时前
前端如何检测用户登录状态是否过期
前端
black^sugar6 小时前
纯前端实现更新检测
开发语言·前端·javascript
寻找沙漠的人6 小时前
前端知识补充—CSS
前端·css