vue框架中如何让大屏页面自适应,方法是什么
Admin 2022-06-30 群英技术资讯 723 次浏览
本文实例为大家分享了Vue实现大屏页面的屏幕自适应的具体代码,供大家参考,具体内容如下
1. 在配置文件设置大屏设计的尺寸1920*1080
//appConfig.js export default{ screen:{ width:1920, height:1080, scale:20 }//大屏设计宽高 }
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函数引入 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得来,这样不用在进行各种换算了
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:mmqy2019@163.com进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
instanceof运算符用于检测构造函数的prototype属性是否出现在某个实例对象的原型链上,本文重点给大家介绍JavaScript手动实现instanceof的问题,感兴趣的朋友跟随小编一起看看吧
jquery修改某一行值的方法:1、利用eq()方法获取指定行元素对象,语法为“元素对象.eq(行元素的索引)”;2、利用html()方法来修改已获取到指定行元素对象的值,语法为“行元素对象.html(修改后的值)”。
这篇文章主要为大家介绍了Electron调用外接摄像头并拍照上传实例实现详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
promise可以处于等待被赋值的等待态(pending),可以给出值并转换为解决态(resolved)。一旦promise被一个值resolve丢失,它将始终保持这个值不再被resolve丢失。
用JavaScript怎样做查询快递单号的功能?一些朋友可能每天都会收到或者寄出很多快递,因此查询快递单号的功能是很重要的,本文给分享模拟京东快递单号查询的功能,实现效果及代码如下,感兴趣的朋友可以参考。
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008