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

JS實(shí)現(xiàn)頁面指定區(qū)域全屏閱讀功能

 更新時(shí)間:2024年06月05日 11:45:59   作者:發(fā)呆小天才yy  
這篇文章主要介紹了JS實(shí)現(xiàn)頁面指定區(qū)域全屏閱讀功能,實(shí)現(xiàn)流程大概是需要在項(xiàng)目中安裝vueuse及需要用到的頁面中引入useFullScreen,本文給大家介紹的非常詳細(xì),需要的朋友可以參考下

這里用到vueuse中的useFullScreen(vueuse中提供了許多封裝好的函數(shù)可以直接使用,極大提高了開發(fā)效率)

詳見vueuse官方文檔:

Home | VueUse

實(shí)現(xiàn)流程

首先需要在項(xiàng)目中安裝vueuse

npm i @vueuse/core

在需要用到的頁面中引入useFullScreen

import { useFullscreen } from '@vueuse/core'

使用(這里用的vue3)

將需要全屏展示的元素用mainele標(biāo)記,作為入?yún)魅雞seFullscreen,獲取全屏展示用到的數(shù)據(jù)

isFullscreen:布爾類型的值,用來判斷當(dāng)前是否是全屏狀態(tài)

toggle:調(diào)用toggle函數(shù)實(shí)現(xiàn)全屏和非全屏的切換

const mainele = ref<HTMLElement | null>(null);
const isFullscreentext = ref("全屏閱讀");
const { isFullscreen, enter, exit, toggle } = useFullscreen(mainele);
const changeFullscreen = () => {
  toggle();
  if (isFullscreen.value) {
    isFullscreentext.value = "全屏閱讀";
  } else {
    isFullscreentext.value = "退出全屏";
  }
};

完整代碼

<template>
  <div>
    <h1 style="text-align: center;">全屏閱讀測(cè)試</h1>
    <div ref="mainele">
      <el-button type="primary" @click="changeFullscreen">{{
        isFullscreentext
      }}</el-button>
      <div style="width: 100%; height: 90vh; background-color: antiquewhite">
        內(nèi)容內(nèi)容內(nèi)容內(nèi)容內(nèi)容
      </div>
    </div>
  </div>
</template>
<script setup lang="ts">
import { ref } from "vue";
import { useFullscreen } from "@vueuse/core";
const mainele = ref<HTMLElement | null>(null);
const isFullscreentext = ref("全屏閱讀");
const { isFullscreen, enter, exit, toggle } = useFullscreen(mainele);
const changeFullscreen = () => {
  toggle();
  if (isFullscreen.value) {
    isFullscreentext.value = "全屏閱讀";
  } else {
    isFullscreentext.value = "退出全屏";
  }
};
</script>

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

相關(guān)文章

最新評(píng)論

新安县| 嘉义县| 馆陶县| 内乡县| 绥芬河市| 温州市| 南和县| 德兴市| 辽中县| 东乡族自治县| 蕲春县| 泸水县| 靖远县| 建始县| 普兰县| 临安市| 孙吴县| 昌宁县| 九龙坡区| 银川市| 萨嘎县| 瓮安县| 澄江县| 隆昌县| 黄石市| 忻城县| 和平县| 梅州市| 扎赉特旗| 海伦市| 华宁县| 文山县| 台江县| 南平市| 那曲县| 蒙城县| 米泉市| 北碚区| 舒城县| 玉门市| 正宁县|