JS實(shí)現(xiàn)頁面指定區(qū)域全屏閱讀功能
這里用到vueuse中的useFullScreen(vueuse中提供了許多封裝好的函數(shù)可以直接使用,極大提高了開發(fā)效率)
詳見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)文章
JS跨域之window.name實(shí)現(xiàn)的跨域數(shù)據(jù)傳輸
這篇文章主要介紹了JS跨域之window.name實(shí)現(xiàn)的跨域數(shù)據(jù)傳輸,需要的朋友可以參考下2022-01-01
js簡(jiǎn)單實(shí)現(xiàn)表單中點(diǎn)擊按鈕動(dòng)態(tài)增加輸入框數(shù)量的方法
這篇文章主要介紹了js簡(jiǎn)單實(shí)現(xiàn)表單中點(diǎn)擊按鈕動(dòng)態(tài)增加輸入框數(shù)量的方法,涉及javascript鼠標(biāo)點(diǎn)擊事件及insertAdjacentHTML方法的相關(guān)使用技巧,需要的朋友可以參考下2015-08-08
uni-app使用swiper實(shí)現(xiàn)輪播圖的方法
做音樂播放器小程序時(shí),因?yàn)閟wiper的問題耽誤不少時(shí)間,所以下面這篇文章主要給大家介紹了關(guān)于uni-app使用swiper實(shí)現(xiàn)輪播圖的相關(guān)資料,需要的朋友可以參考下2022-11-11
JavaScript實(shí)現(xiàn)的簡(jiǎn)單Tab點(diǎn)擊切換功能示例
這篇文章主要介紹了JavaScript實(shí)現(xiàn)的簡(jiǎn)單Tab點(diǎn)擊切換功能,涉及JavaScript事件響應(yīng)及頁面元素屬性動(dòng)態(tài)操作相關(guān)實(shí)現(xiàn)技巧,需要的朋友可以參考下2018-07-07

