vue大屏展示適配的方法
本文實(shí)例為大家分享了vue大屏展示適配的具體代碼,供大家參考,具體內(nèi)容如下
1.utils文件夾建一個(gè)文件cv以下代碼
export function useIndex (appRef) {
// * appRef指向最外層容器
// * 定時(shí)函數(shù)
let timer = null
// * 默認(rèn)縮放值
const scale = {
width: '1',
height: '1'
}
// * 設(shè)計(jì)稿尺寸(px)
const baseWidth = 1920
const baseHeight = 1080
// * 需保持的比例(默認(rèn)2)
// const baseProportion = parseFloat((baseWidth / baseHeight).toFixed(5))
const baseProportion = 2
const calcRate = () => {
// 當(dāng)前寬高比
const currentRate = parseFloat((window.innerWidth / window.innerHeight).toFixed(5))
if (appRef) {
if (currentRate > baseProportion) {
// 表示更寬
scale.width = ((window.innerHeight * baseProportion) / baseWidth).toFixed(5)
scale.height = (window.innerHeight / baseHeight).toFixed(5)
appRef.style.transform = `scale(${scale.width}, ${scale.height}) translate(-50%, -50%)`
} else {
// 表示更高
scale.height = ((window.innerWidth / baseProportion) / baseHeight).toFixed(5)
scale.width = (window.innerWidth / baseWidth).toFixed(5)
appRef.style.transform = `scale(${scale.width}, ${scale.height}) translate(-50%, -50%)`
}
}
}
const resize = () => {
clearTimeout(timer)
timer = setTimeout(() => {
calcRate()
}, 200)
}
// 改變窗口大小重新繪制
const windowDraw = () => {
window.addEventListener('resize', resize)
}
return {
appRef,
calcRate,
windowDraw
}
}
2.app.vue結(jié)構(gòu)樣式
<template>
<div ref="appRef" class="main">
<div class="layout-container">
</div>
</div>
</template>
<script>
import { useIndex } from '@/utils/utilsDram.js'
export default {
mounted () {
const { calcRate, windowDraw } =useIndex(this.$refs.appRef)
calcRate()
windowDraw()
}
}
</script>
<style lang="scss" scoped>
.main {
color: #d3d6dd;
width: 1920px;
height: 1080px;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
transform-origin: left top;
.layout-container {
width: 100%;
height: 100%;
}
}
</style>
3.字體大小盒子寬度直接設(shè)置px不管放大縮小都是最初的樣子,基本頁面大小不會(huì)相差太遠(yuǎn),下圖是頁面放大500倍的效果

以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
Vue router/Element重復(fù)點(diǎn)擊導(dǎo)航路由報(bào)錯(cuò)問題及解決
這篇文章主要介紹了Vue router/Element重復(fù)點(diǎn)擊導(dǎo)航路由報(bào)錯(cuò)問題及解決方案,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2022-07-07
vue3響應(yīng)式轉(zhuǎn)換常用API操作示例代碼
在Vue 3中,響應(yīng)式系統(tǒng)得到了顯著改善,包括使用Composition API時(shí)更加靈活的狀態(tài)管理,這篇文章主要介紹了vue3響應(yīng)式轉(zhuǎn)換常用API操作示例代碼,需要的朋友可以參考下2024-08-08
詳解vue2.0組件通信各種情況總結(jié)與實(shí)例分析
本篇文章主要介紹了詳解vue2.0組件通信各種情況總結(jié)與實(shí)例分析,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-03-03
使用vue-router為每個(gè)路由配置各自的title
這篇文章主要介紹了如何使用vue-router為每個(gè)路由配置各自的title,及使用vue router的方法,需要的朋友可以參考下2018-07-07
vue使用富文本編輯器vue-quill-editor的操作指南和注意事項(xiàng)
vue中很多項(xiàng)目都需要用到富文本編輯器,在使用了ueditor和tinymce后,發(fā)現(xiàn)并不理想,所以果斷使用vue-quill-editor來實(shí)現(xiàn),下面這篇文章主要給大家介紹了關(guān)于vue使用富文本編輯器vue-quill-editor的操作指南和注意事項(xiàng),需要的朋友可以參考下2023-05-05
vue實(shí)現(xiàn)消息的無縫滾動(dòng)效果的示例代碼
本篇文章主要介紹了vue實(shí)現(xiàn)消息的無縫滾動(dòng)效果的示例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-12-12
v-if 導(dǎo)致 elementui 表單校驗(yàn)失效問題解決方案
在使用 elementui 表單的過程中,某些表單項(xiàng)需要通過 v-if 來判斷是否展示,但是這些表單項(xiàng)出現(xiàn)了檢驗(yàn)失效的問題,今天小編給大家介紹v-if 導(dǎo)致 elementui 表單校驗(yàn)失效問題解決方案,感興趣的朋友一起看看吧2024-01-01

