0
点赞
收藏
分享

微信扫一扫

浏览器全屏的时候监听键盘事件

老王420 2022-01-17 阅读 62

今天在写代码的时候有个需求,全屏的时候监听esc触发事件(改变data值的状态),
浏览器规定好像全屏的时候监听不了键盘事件,so、、、只能判断浏览器是否是全屏状态


created(){
			window.onresize = ()=> {
				if(!this.checkFull()){
					// 退出全屏后要执行的动作
					console.log("退出全屏")
					
				}
		},
methods:{
	checkFull() {
		var isFull =
		 document.fullscreenEnabled ||
		 window.fullScreen || 
		 document.webkitIsFullScreen ||
		 document.msFullscreenEnabled;
	      if (isFull === undefined) {
	          isFull = false;
	      }
	      return isFull;
	    }
   },

差不多就是这个逻辑

举报

相关推荐

0 条评论