vue框架中如何让大屏页面自适应,方法是什么
Admin 2022-06-30 群英技术资讯 675 次浏览
本文实例为大家分享了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进行举报,并提供相关证据,查实之后,将立刻删除涉嫌侵权内容。
猜你喜欢
Javascript查看大图功能代码实现,点击小图片可以查看大图,就是把大图放置在顶层(z-index大于当前页面的),并且还可以加一些额外的比如透明度什么的。
JavaScript中的变量是松散类型的,可以保存任何类型数据,变量只不过是一个名称,下面这篇文章主要给大家介绍了关于JavaScript变量声明的var、let、const的相关资料,需要的朋友可以参考下
简单复制对象的最外层属性,不处理对象更深层次的对象属性,会导致复制对象和原始对象的深层次属性指向同一个内存。如果一个对象改变了内存的地址,就会影响另一个对象。
这篇文章我们来了解jQuery如何改变对象的值,这里使用val()方法来实现,实现代码如下,有需要的朋友可以参考,接下来就跟随小编来一起学习一下吧!
这篇文章主要为大家详细介绍了js实现新闻轮播效果,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
成为群英会员,开启智能安全云计算之旅
立即注册Copyright © QY Network Company Ltd. All Rights Reserved. 2003-2020 群英 版权所有
增值电信经营许可证 : B1.B2-20140078 粤ICP备09006778号 域名注册商资质 粤 D3.1-20240008