vue中實(shí)現(xiàn)點(diǎn)擊變成全屏及縮放功能
項(xiàng)目中有點(diǎn)擊按鈕實(shí)現(xiàn)全屏功能
方式一:js實(shí)現(xiàn)全屏
<template> <div> <a-button type="primary" @click="screen">全屏</a-button> </div> </template>
data:
data() { return { fullscreen: false }; },
methods:
screen() { 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; },
方式二:使用的是sreenfull插件,執(zhí)行命令安裝
npm install --save screenfull
在使用的頁面正確引入:
import screenfull from ‘screenfull'
代碼如下:
<template> <div> <a-button type="primary" @click="screen">全屏</a-button> <div> </template>
data:
data() { return { fullscreen: false }; },
methods:
screen() { // 如果不允許進(jìn)入全屏,發(fā)出不允許提示 if (!screenfull.enabled) { this.$message("您的瀏覽器不能全屏"); return false; } screenfull.toggle(); this.$message.success("全屏啦"); },
效果圖:
實(shí)用?。。?/p>
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
淺談vue,angular,react數(shù)據(jù)雙向綁定原理分析
本篇文章主要介紹了淺談vue,angular,react數(shù)據(jù)雙向綁定原理分析,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-11-11vue百度地圖修改折線顏色,添加icon和文字標(biāo)注方式
這篇文章主要介紹了vue百度地圖修改折線顏色,添加icon和文字標(biāo)注方式,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-03-03使用WebStorm導(dǎo)入已有Vue項(xiàng)目并運(yùn)行的詳細(xì)步驟與注意事項(xiàng)
這篇文章主要介紹了如何使用WebStorm導(dǎo)入、運(yùn)行和管理Vue項(xiàng)目,包括環(huán)境配置、Node.js和npm版本管理、項(xiàng)目依賴管理以及常見問題的解決方案,文中通過代碼介紹的非常詳細(xì),需要的朋友可以參考下2024-11-11vue-cli項(xiàng)目中img如何使用require動(dòng)態(tài)獲取圖片
這篇文章主要介紹了vue-cli項(xiàng)目中img如何使用require動(dòng)態(tài)獲取圖片,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。2022-09-09vuejs element table 表格添加行,修改,單獨(dú)刪除行,批量刪除行操作
這篇文章主要介紹了vuejs element table 表格添加行,修改,單獨(dú)刪除行,批量刪除行操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2020-07-07在vue中把含有html標(biāo)簽轉(zhuǎn)為html渲染頁面的實(shí)例
今天小編就為大家分享一篇在vue中把含有html標(biāo)簽轉(zhuǎn)為html渲染頁面的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2019-10-10Vue CLI3中使用compass normalize的方法
這篇文章主要介紹了Vue CLI3中使用compass normalize的方法,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2019-05-05vue+elementUI實(shí)現(xiàn)動(dòng)態(tài)面包屑
這篇文章主要為大家詳細(xì)介紹了vue+elementUI實(shí)現(xiàn)動(dòng)態(tài)面包屑,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-04-04