本文实例为大家分享了Vue使用screenfull实现全屏的具体代码,供大家参考,具体内容如下
安装
1
|
npm install --save screenfull |
在需要的页面引用
1
|
import screenfull from 'screenfull' |
全屏使用
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
< template > < span @ click = 'clickFullscreen' >全屏</ span > </ template > < script > import screenfull from 'screenfull' export default{ name: 'screenfull', data(){ return { isFullscreen: false } }, methods:{ clickFullscreen(){ if (!screenfull.isEnabled) { this.$message({ message: 'you browser can not work', type: 'warning' }) return false } screenfull.toggle() } } } </ script > |
原生实现方法
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
// 全屏事件 兼容 clickFullscreen() { let element = document.documentElement; if ( this .isFullscreen) { if (document.exitFullscreen) { document.exitFullscreen(); } else if (document.webkitCancelFullScreen) { document.webkitCancelFullScreen(); } else if (document.mozCancelFullScreen) { document.mozCancelFullScreen(); } else if (document.msExitFullscreen) { document.msExitFullscreen(); } } else { if (element.requestFullscreen) { element.requestFullscreen(); } else if (element.webkitRequestFullScreen) { element.webkitRequestFullScreen(); } else if (element.mozRequestFullScreen) { element.mozRequestFullScreen(); } else if (element.msRequestFullscreen) { // IE11 element.msRequestFullscreen(); } } this .isFullscreen= ! this .isFullscreen; } |
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。
原文链接:https://blog.csdn.net/weixin_46034375/article/details/108603166