当前位置:网站首页>移动端适配方案
移动端适配方案
2022-06-13 05:42:00 【霹雳桃】
移动端适应性布局
- 使用 rem 尺寸单位来实现
方案一
1.使用 less 配置,引入 lib-flexible 插件,或者自己获取 设备宽度计算
使用 less 自己配置
- 统一样式通过变量实现
- 统一共有样式抽离通过 mixin 混入实现
自己配置 js 文件,计算 rem 的值
- 在 index.html 中配置,设置根元素字体大小
// 设置 minimum-scale=1,maximum-scale=1 设置初始倍数 // 配置是否允许用户缩放
<meta name="viewport" content="width=device-width,initial-scale=1.0,minimum-scale=1,maximum-scale=1,user-scaleable=no" />
// 将根元素字体大小和屏幕做绑定
document.documentElement.style.fontSize =
document.documentElement.clientWidth / 10 + "px";
// 屏幕改变重设根元素字体大小
window.addEventListener("resize", () => {
document.documentElement.style.fontSize =
document.documentElement.clientWidth / 10 + "px";
});
less 配置
- 引入文件 index.less mixin.less variable.less 设置 rem 大小
方案二
使用 lib-flexible 插件
- 1.安装
npm i lib-flexible -S - 2.首先要引入到 main.js 中
import "lib-flexible" - 3.使用 flexible 所有单位要用 rem
webpack 帮助我们实现 px 转 rem 的库,,叫做 px2rem
- 1.安装
npm install px2remnpm install px2rem-loader
- 2.插件配置
- 在 vue.config.js s中配置
chainWebpack: (config) => {
config.module
.rule("less") // css 规则
.oneOf("vue")
.use("px2rem-loader")
.loader("px2rem-loader")
.before("postcss-loader") // this makes it work.
.options({
remUnit: 37.5, // 设计 分辨率尺寸
remPrecision: 8, // rem 小数保留几位
}) // remUnit: 192代表以1920px为整体,如果设计稿的尺寸是750px,这里的值为75
.end();
},
3.使用
- 如果哪一个样式的 px 不需要转换 rem 的话,就在后面加上
/*no*/
.text { width: 300px; height: 300px; /*no*/ }- 如果哪一个样式的 px 不需要转换 rem 的话,就在后面加上
对比 mixin 和 px2rem 实现 rem 的转换
实现原理 都是 px/baseSize + ‘rem’
mixin 需要的才去写
px2rem 全部转化不需要的自己加 /no/
边栏推荐
- Nacos series registry principle and source code analysis
- 12 error end event and terminateendevent of end event
- Integer tips
- Three paradigms of MySQL
- Current limiting and fusing of gateway gateway in Spirng cloud
- Solve the problem of garbled code in the MySQL execution SQL script database in docker (no need to rebuild the container)
- 通过命令行创建harbor镜像库
- One of PowerShell optimizations: prompt beautification
- Jeffery0207 blog navigation
- Comment procéder à l'évaluation des algorithmes
猜你喜欢

Case - recursive factorial (recursive)

About Evaluation Metrics

OpenGL馬賽克(八)

安装harbor(在线|离线)

MySQL table data modification

10 signalstartevent and signalcatchingevent of flowable signal events

SQL table columns and statements of database

About anonymous inner classes

How to Algorithm Evaluation Methods

MySQL performs an inner join on query. The query result is incorrect because the associated fields have different field types.
随机推荐
Case -- the HashSet set stores the student object and traverses
设置自定义dialog的正确宽高
Create a harbor image library from the command line
Case - traversing the directory (file class & recursive call)
ZABBIX wechat alarm
使用cmake交叉編譯helloworld
12 error end event and terminateendevent of end event
Understanding of speech signal framing
1 Introduction to drools rule engine (usage scenarios and advantages)
Unity game optimization [Second Edition] learning record 6
Windbos run command set
OpenGL Mosaic (8)
Solutions to conflicts between xampp and VMware port 443
Comment procéder à l'évaluation des algorithmes
Agile conflicts and benefits
2021.9.29学习日志-MIME类型
MySQL fuzzy query and sorting by matching degree
2021.9.29 learning log restful architecture
Django uploads local binaries to the database filefield field
Case - count the number of occurrences of each string in the string