最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

vue實(shí)現(xiàn)視頻全屏切換功能

 更新時(shí)間:2023年11月08日 15:08:25   作者:﹏????  
這篇文章主要為大家詳細(xì)介紹了如何使用vue實(shí)現(xiàn)視頻全屏切換的功能,文中的示例代碼講解詳細(xì), 具有一定的借鑒價(jià)值,有需要的小伙伴可以參考一下

最近項(xiàng)目開發(fā)中遇到一個(gè)視頻窗口全屏切換功能,為此在這里做個(gè)記錄。

具體的實(shí)現(xiàn)思路:

<template>
  <div class="content-box">
    <div class="container">
      <div id="screen" class="screen">
        <el-button @click="screen()">
          {{ fullscreen ? "還原" : "最大化" }}
        </el-button>
      </div>
    </div>
  </div>
</template>
 
<script>
export default {
  data() {
    return {
      fullscreen: false,
    };
  },
  mounted() {
    window.addEventListener("resize", ()=> {
      if (!this.isFullScreen()) {
        // 非全屏狀態(tài)
        this.fullscreen = false;
      }
    });
  },
  methods: {
    //判斷是否全屏
    isFullScreen() {
      return !!(document.webkitIsFullScreen || this.fullele());
    },
    fullele() {
      return (
        document.fullscreenElement ||
        document.webkitFullscreenElement ||
        document.msFullscreenElement ||
        document.mozFullScreenElement ||
        null
      );
    },
    screen() {
      let element = document.getElementById("screen");
      if (this.fullscreen) {
        // 關(guān)閉全屏
        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;
    },
  },
};
</script>
 
<style lang="scss" scoped>
.screen {
  width: 500px;
  height: 500px;
  background-color: #fff;
  border: 1px solid red;
}
</style>

這里需要監(jiān)聽ESC鍵,為此做了特殊處理,這里是Demo,跟使用效果圖基本差不多

知識(shí)補(bǔ)充

除了實(shí)現(xiàn)視頻全屏切換,vue還可以實(shí)現(xiàn)瀏覽器全屏以及退出全屏,下面是實(shí)現(xiàn)代碼,希望對(duì)大家有所幫助

在src/utils/util.js中加入下面代碼塊

import Vue from 'vue'
const util = Vue.prototype.util = {}
// 切換全屏
util.fullScreen = function (element) {
    element = element || document.body;
    if (element.requestFullscreen) {
        element.requestFullscreen();
    } else if (element.mozRequestFullScreen) {
        element.mozRequestFullScreen();
    } else if (element.webkitRequestFullscreen) {
        element.webkitRequestFullscreen();
    } else if (element.msRequestFullscreen) {
        element.msRequestFullscreen();
    }
}

// 退出全屏
util.exitFullscreen = function () {
    if (document.exitFullscreen) {
        document.exitFullscreen();
    } else if (document.mozCancelFullScreen) {
        document.mozCancelFullScreen();
    } else if (document.webkitExitFullscreen) {
        document.webkitExitFullscreen();
    }
}
export {
    util
}

2.在頁面中使用全屏/退出全屏

<template>
	<div class="header">
         <!-- 全屏 -->
         <a v-if="fullScreenFlag" href="javascript:;" rel="external nofollow"  rel="external nofollow"  class="iconfont iconquanping" title="全屏" @click="fullScreen()"></a>
         <!-- 退出全屏 -->
         <a v-else href="javascript:;" rel="external nofollow"  rel="external nofollow"  class="iconfont icontuichuquanping1" title="退出全屏" @click="exitFullScreen()"></a>
	</div>
</template>
<script>
export default {
	data () {
		return {
            fullScreenFlag: true,
		};
    },
	methods: {
        // 全屏
        fullScreen(){
            this.fullScreenFlag = false;
            this.util.fullScreen();
        },
        // 退出全屏
        exitFullScreen() {
            this.fullScreenFlag = true;
            this.util.exitFullscreen();
        },
    },
};
</script>

到此這篇關(guān)于vue實(shí)現(xiàn)視頻全屏切換功能的文章就介紹到這了,更多相關(guān)vue視頻全屏切換內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue實(shí)現(xiàn)nav導(dǎo)航欄的方法

    vue實(shí)現(xiàn)nav導(dǎo)航欄的方法

    這篇文章主要為大家詳細(xì)介紹了vue項(xiàng)目nav導(dǎo)航欄的實(shí)現(xiàn)方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-12-12
  • 詳解Jest結(jié)合Vue-test-utils使用的初步實(shí)踐

    詳解Jest結(jié)合Vue-test-utils使用的初步實(shí)踐

    這篇文章主要介紹了詳解Jest結(jié)合Vue-test-utils使用的初步實(shí)踐,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-06-06
  • Vue中$refs的用法詳解

    Vue中$refs的用法詳解

    這篇文章主要介紹了Vue中$refs的用法,非常不錯(cuò),具有一定的參考借鑒價(jià)值 ,需要的朋友可以參考下
    2018-06-06
  • vue2.0開發(fā)入門筆記之.vue文件的生成和使用

    vue2.0開發(fā)入門筆記之.vue文件的生成和使用

    本篇文章主要介紹了vue2.0開發(fā)入門筆記之.vue文件的生成和使用 ,非常具有實(shí)用價(jià)值,需要的朋友可以參考下
    2017-09-09
  • 詳解Vue如何實(shí)現(xiàn)字母驗(yàn)證碼

    詳解Vue如何實(shí)現(xiàn)字母驗(yàn)證碼

    這篇文章主要為大家介紹了Vue如何實(shí)現(xiàn)字母驗(yàn)證碼詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-05-05
  • 詳解Vue webapp項(xiàng)目通過HBulider打包原生APP

    詳解Vue webapp項(xiàng)目通過HBulider打包原生APP

    這篇文章主要介紹了詳解Vue webapp項(xiàng)目通過HBulider打包原生APP,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-06-06
  • vue項(xiàng)目element UI input框掃碼槍掃描過快出現(xiàn)數(shù)據(jù)丟失問題及解決方案

    vue項(xiàng)目element UI input框掃碼槍掃描過快出現(xiàn)數(shù)據(jù)丟失問題及解決方案

    這篇文章主要介紹了vue項(xiàng)目element UI input框掃碼槍掃描過快出現(xiàn)數(shù)據(jù)丟失問題,輸入框要掉兩個(gè)接口,根據(jù)第一個(gè)驗(yàn)證接口返回的code,彈不同的框,點(diǎn)擊彈框確認(rèn)再掉第二個(gè)接口,需要的朋友可以參考下
    2022-12-12
  • vue項(xiàng)目如何刪除無用的依賴詳解

    vue項(xiàng)目如何刪除無用的依賴詳解

    vue是目前非常流行的前端開發(fā)框架,隨著技術(shù)的不斷更新,我們也需要更新我們的vue項(xiàng)目,這篇文章主要給大家介紹了關(guān)于vue項(xiàng)目如何刪除無用的依賴的相關(guān)資料,需要的朋友可以參考下
    2024-09-09
  • 簡(jiǎn)易Vue評(píng)論框架的實(shí)現(xiàn)(父組件的實(shí)現(xiàn))

    簡(jiǎn)易Vue評(píng)論框架的實(shí)現(xiàn)(父組件的實(shí)現(xiàn))

    本篇文章主要介紹了簡(jiǎn)易 Vue 評(píng)論框架的實(shí)現(xiàn)(父組件的實(shí)現(xiàn)),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2018-01-01
  • Vue3導(dǎo)出pdf文件詳細(xì)方案

    Vue3導(dǎo)出pdf文件詳細(xì)方案

    這篇文章主要給大家介紹了關(guān)于Vue3導(dǎo)出pdf文件的相關(guān)資料,最近項(xiàng)目有個(gè)需求,將系統(tǒng)統(tǒng)計(jì)的數(shù)據(jù)生成分析報(bào)告,然后可以導(dǎo)出成PDF,這里給大家總結(jié)下,需要的朋友可以參考下
    2023-08-08

最新評(píng)論

视频| 汉川市| 柳林县| 六盘水市| 益阳市| 麦盖提县| 伊宁县| 琼中| 宜春市| 松阳县| 南宁市| 车险| 方正县| 秦安县| 横山县| 棋牌| 通海县| 论坛| 玉林市| 雷山县| 剑河县| 连城县| 句容市| 威海市| 新蔡县| 峡江县| 元朗区| 岗巴县| 开江县| 山阴县| 通许县| 修水县| 闽清县| 水城县| 阳曲县| 理塘县| 右玉县| 莲花县| 随州市| 普定县| 康乐县|