自适应的屏幕 lib-flexible 和 v-scale-screen
首先是要安装
npm install lib-flexible --save
然后在 修改
这个根据设计稿的大小来计算 这个是 把屏幕设计成24份 1920/24 80px=1rem
-
-
function refreshRem(){
-
var width = docEl.getBoundingClientRect().width;
-
if (width / dpr > 1920) {
-
width = 1920 * dpr;
-
}
-
var rem = width / 24;
-
docEl.style.fontSize = rem 'px';
-
flexible.rem = win.rem = rem;
-
}
一定要引入啊
-
// px2rem 自适应
-
import 'lib-flexible'
然后在软件中安装插件
随后在设置中
这个 80 是 上面设计稿出来的结果 根据自己的需要来写啊
第二种是 v-scale-screen
首先是 安装
根据自己的vue版本 来安装不同的 v-scale-screen的版本
vue2请使用1.x版本、vue2请使用1.x版本、vue2请使用1.x版本,重要的事情说三遍
注:使用时请将
body
样式设置为overflow: hidden;
注:使用时请将body
样式设置为overflow: hidden;
注:使用时请将body
样式设置为overflow: hidden;
例如 安装: 我安装的是 vue2 的啊
npm i v-scale-screen@1.0.2
使用
-
// main.js
-
import Vue from "vue";
-
import VScaleScreen from 'v-scale-screen'
-
-
Vue.use(VScaleScreen)
上面是代码可以直接复制 下面是图片
使用的地方如下
-
<template>
-
<!-- width="1920" height="1080" 可写可不写额 -->
-
<v-scale-screen fullScreen width="1920" height="1080" >
-
<div class="a">
-
<div class="c"></div>
-
</div>
-
<div class="b"></div>
-
</v-scale-screen>
-
</template>
-
-
<script>
-
-
export default {
-
data() {
-
return {
-
-
};
-
},
-
mounted() {
-
},
-
methods: {},
-
};
-
</script>
-
<style lang="less" scoped>
-
.a {
-
width: 540px;
-
height: 540px;
-
background-color: red;
-
display: flex;
-
justify-content: center;
-
align-items: center;
-
}
-
.b {
-
width: 540px;
-
height: 540px;
-
background-color: rgb(24, 20, 228);
-
}
-
.c {
-
width: 400px;
-
height: 200px;
-
background: rebeccapurple;
-
}
-
</style>
api:
最重要的一点 记得这个标签
-
<v-scale-screen >
-
<div class="a">
-
<div class="c"></div>
-
</div>
-
<div class="b"></div>
-
</v-scale-screen>
另外还是有样式的调整 在公共的位置
-
* {
-
margin: 0;
-
padding: 0;
-
}
-
body {
-
overflow: hidden;
-
}
-
.screen-box {
-
background: #fff !important;
-
}
-
.screen-wrapper{
-
margin: 0 !important;
-
}
具体的位置在
再页面上的显示效果
100%
50%
125%
vue3的用法
Vue3
我们在vue3中以组件方式导出
<template> <v-scale-screen width="1920" height="1080"> <div> <v-chart>....</v-chart> <v-chart>....</v-chart> <v-chart>....</v-chart> <v-chart>....</v-chart> <v-chart>....</v-chart> </div> </v-scale-screen> </template> <script> import { defineComponent } from "vue" import VScaleScreen from 'v-scale-screen' export default defineComponent({ name:'Demo', components:{ VScaleScreen } }) </script>注:使用时请将
body
样式设置为overflow: hidden;
注:使用时请将body
样式设置为overflow: hidden;
注:使用时请将body
样式设置为overflow: hidden;
用法:
npm install v-scale-screen # or yarn add v-scale-screen
新增屏幕适配 GitHub - hangjob/flexible-pc: rem布局 ,16:9的比列,适配1440px 以上的所有大屏幕GitHub - hangjob/flexible-pc: rem布局 ,16:9的比列,适配1440px 以上的所有大屏幕
这篇好文章是转载于:学新通技术网
- 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
- 本站站名: 学新通技术网
- 本文地址: /boutique/detail/tanhchjbja
-
photoshop蒙版画笔没反应怎么办
PHP中文网 06-24 -
微信小程序没声音怎么办
PHP中文网 06-15 -
excel图片置于文字下方的方法
PHP中文网 06-27 -
微信提示登录环境异常是什么意思原因
PHP中文网 04-09 -
微信运动停用后别人还能看到步数吗
PHP中文网 07-22 -
微信人名旁边有个图标有什么用
PHP中文网 03-11 -
使用云服务器搭建个人游戏加速器教程
AuroraJay 07-06 -
Excel筛选和排序是灰色的怎么办
PHP中文网 06-22 -
抖音国际版要用什么加速器能流畅刷Tiktok的加速器
TK小达人 08-02 -
键盘上的负数是哪个键
PHP中文网 03-17