本文实例为大家分享了vue全屏事件开发的具体代码,供大家参考,具体内容如下
在项目中有需求相应浏览器全屏,写了个案例代码
先看看效果吧
全屏显示:
html代码:
<!-- el-tooltip 文字提示 --> <div class="btn-fullscreen" @click="handleFullScreen"> <el-tooltip effect="dark" :content="fullscreen " placement="bottom"> <i class="el-icon-rank"></i> </el-tooltip> </div>
js代码
data(){ return { fullscreen: false } } // 全屏事件 handleFullScreen(){ 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; },
通过fullscreen判断的true和false确定是否相应全屏
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。