Vue實(shí)現(xiàn)大屏頁(yè)面的屏幕自適應(yīng)
本文實(shí)例為大家分享了Vue實(shí)現(xiàn)大屏頁(yè)面的屏幕自適應(yīng)的具體代碼,供大家參考,具體內(nèi)容如下
1. 在配置文件設(shè)置大屏設(shè)計(jì)的尺寸1920*1080
//appConfig.js
export default{
screen:{
width:1920,
height:1080,
scale:20
}//大屏設(shè)計(jì)寬高
}
2. 定義resetScreenSize.js
import appConfig from '../config/base'
export function pageResize(callback) {
let init = () => {
console.log(window.innerHeight + "," + window.innerWidth);
let _el = document.getElementById('app');
let hScale = window.innerHeight / appConfig.screen.height;
let wScale = window.innerWidth / appConfig.screen.width;
let pageH = window.innerHeight;
let pageW = window.innerWidth;
let isWider = (window.innerWidth / window.innerHeight) >= (appConfig.screen.width / appConfig.screen.height);
console.log(isWider);
if (isWider) {
_el.style.height = window.innerHeight+'px';// '100%';
_el.style.width = pageH * appConfig.screen.width / appConfig.screen.height + 'px';
_el.style.top='0px';
_el.style.left=(window.innerWidth -pageH * appConfig.screen.width / appConfig.screen.height)*0.5+'px';
console.log(_el.style.width + "," + _el.style.height)
}
else {
_el.style.width = window.innerWidth+'px';// '100%';
_el.style.height = pageW * appConfig.screen.height / appConfig.screen.width + 'px';
_el.style.top= 0.5*(window.innerHeight-pageW * appConfig.screen.height / appConfig.screen.width)+'px';
_el.style.left='0px';
console.log(_el.style.height);
console.log(_el.style.top);
}
document.documentElement.style.fontSize = (_el.clientWidth / appConfig.screen.scale) + 'px';
}
var resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize';
window.addEventListener(resizeEvt, init, false);
document.documentElement.addEventListener('DOMContentLoaded', init, false);
init()
}
3 使用方式
main.js 引入
import appConfig from './config/base.js';
Vue.prototype.appConfig=appConfig;
app.Vue 在mounted函數(shù)引入
import {pageResize} from './utils/resetScreenSize'
export default {
name: 'App',
data(){
return{
}
},
mounted(){
pageResize();
console.log('pageResize');
}
}
組件中樣式 lang="stylus"
.mc{
display :flex;
flex-direction :column;
align-content :center;
justify-content :center;
display: flex;
flex: 1 1 auto;
flex-direction: column;
padding:(15/96)rem;
}
.leftC{
width :(410/96)rem;
}
.centerC{
width :(1060/96)rem;
}
.rightC{
width :(450/96)rem;
}
其中 96為 配置文件中1920/20得來(lái),這樣不用在進(jìn)行各種換算了
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
vue實(shí)現(xiàn)的樹(shù)形結(jié)構(gòu)加多選框示例
這篇文章主要介紹了vue實(shí)現(xiàn)的樹(shù)形結(jié)構(gòu)加多選框,結(jié)合實(shí)例形式分析了在之前遞歸組件實(shí)現(xiàn)vue樹(shù)形結(jié)構(gòu)的基礎(chǔ)之上再加上多選框功能相關(guān)操作技巧,需要的朋友可以參考下2019-02-02
vue使用JSON編輯器:vue-json-editor詳解
文章介紹了如何在Vue項(xiàng)目中使用JSON編輯器插件`vue-json-editor`,包括安裝、引入、注冊(cè)和使用示例,通過(guò)這些步驟,用戶(hù)可以在Vue應(yīng)用中輕松實(shí)現(xiàn)JSON數(shù)據(jù)的編輯功能,文章最后呼吁大家支持腳本之家2025-01-01
Vue使用Tinymce富文本自定義toolbar按鈕的實(shí)踐
本文主要介紹了Vue使用Tinymce富文本自定義toolbar按鈕,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-12-12
基于vuex實(shí)現(xiàn)購(gòu)物車(chē)功能
這篇文章主要為大家詳細(xì)介紹了基于vuex實(shí)現(xiàn)購(gòu)物車(chē)功能,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-01-01
vue3+TS 實(shí)現(xiàn)自定義指令長(zhǎng)按觸發(fā)綁定的函數(shù)
這篇文章主要介紹了vue3+TS實(shí)現(xiàn)自定義指令長(zhǎng)按觸發(fā)綁定的函數(shù),文中給大家分享了編寫(xiě)自定義指令時(shí)遇到的幾個(gè)難點(diǎn),本文結(jié)合實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友可以參考下2022-12-12
使用vue點(diǎn)擊li,獲取當(dāng)前點(diǎn)擊li父輩元素的屬性值方法
今天小編就為大家分享一篇使用vue點(diǎn)擊li,獲取當(dāng)前點(diǎn)擊li父輩元素的屬性值方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2018-09-09

