当前位置:网站首页>移动端适配方案
移动端适配方案
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/
边栏推荐
- OpenGL马赛克(八)
- MySQL installation in Linux Environment
- Case - the list set stores student objects and traverses them in three ways
- Case - grade sorting - TreeSet set storage
- 2021.9.30 learning log -postman
- 2021.9.29 learning log MIME type
- JS output uincode code
- NVIDIA Jetson nano/xavier NX capacity expansion tutorial
- 18 flowable task manualtask and receivetask
- Fast power code
猜你喜欢

Case - simulated landlords (upgraded version)

KVM hot migration for KVM virtual management

2 first experience of drools

float类型取值范围

Vagrant virtual machine installation, disk expansion and LAN access tutorial

Small project - household income and expenditure software (1)

Use of natural sorting comparable

Metartc4.0 integrated ffmpeg compilation

1 Introduction to drools rule engine (usage scenarios and advantages)

Web site learning and sorting
随机推荐
Case - count the number of occurrences of each string in the string
KVM hot migration for KVM virtual management
NVIDIA Jetson Nano/Xavier NX 扩容教程
Set the correct width and height of the custom dialog
Float type value range
Summary of the 11th week of sophomore year
A fast week
Building a stand-alone version of Nacos series
2021.9.29 learning log MIME type
Integer tips
设置自定义dialog的正确宽高
基于 Docker Compose 搭建 Nacos 2(使用 MySQL 进行持久化)
OpenGL Mosaic (8)
MySQL built-in functions
Unity game optimization (version 2) learning record 7
Understanding of speech signal framing
安装harbor(在线|离线)
Comment procéder à l'évaluation des algorithmes
Use of natural sorting comparable
Unity游戏优化(第2版)学习记录7