vue 实现全屏功能

2022-10-21  本文已影响0人  lvyweb

html

 <el-button  @click="toFullScreen" style="margin-left:10px;font-size:16px">
       <el-icon><FullScreen /></el-icon>
</el-button>

事件部分

 data(){
    return{
        fullscreen:false
    }
 },
  methods:{
    // 全屏方法
    toFullScreen () {
      let element = document.documentElement;
      if (this.fullscreen) {
        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.fullscreen = !this.fullscreen;
    }
  }

上一篇 下一篇

猜你喜欢

热点阅读