网页全屏自定义内容如何实现?

 

 

使

 

screenfull 使 JavaScript Fullscreen api  

 

npm install --save screenfull

使

import screenfull from 'screenfull'

 

screenfull 

2.1screenfull.enabled 

 Boolean 

2.2 screenfull.isFullscreen

 Boolean 

2.3 screenfull.toggle()

退退

2.4 screenfull.request()

退使 DOM 

2.5 screenfull.on


screenfull.on('change', () => {        

   console.log('' );  

});

 


screenfull.on('error', () => {        

   console.log('' );  

});

 

2.6 screenfull.off

screenfull.off('change', callback);

callback 

使

Demo

<template>
 <div class="event-con">
  大容器
  <div class="detail" >
   <div class="selected-event" >
    内容1
   </div>
   <div
    class="detail-module"
    :class="[isFull ? 'fullScreen-con' : 'notFull']"
     ref="fullDom"
     >
     内容2
   </div>
  </div>
 </div>
</template>

<script>
import screenfull from 'screenfull''
export default {
 data() {
  return {
   isFull: false,
  }
 },
 created() {
  if (screenfull.enabled) {
   screenfull.on('change', () => {
    console.log('全屏事件监听', screenfull.isFullscreen)
    if (screenfull.isFullscreen) {
     this.isFull = true
    } else {
     this.isFull = false
    }
   })
  }
 },
 beforeDestroy() {
  screenfull.off('change')
 },
 methods: {
  toggleScreen() {
   // 判断是否可用
   if (!screenfull.enabled) {
    // 此时全屏不可用
    this.$message.warning('此时全屏组件不可用')
     return
   }
    //   如果可用 就可以全屏
    if (screenfull.isFullscreen) {
     screenfull.toggle()
    } else {
     screenfull.request(this.$refs.fullDom)
    }
   },
 }
}
</script>

<style lang="scss" scoped>

</style>

  


 

 Bug Debug 

 + ❤️ 

posted @ 2023-07-15 10:55  前端人  阅读(262)  评论(0编辑  收藏  举报