当前位置:网站首页>移动端vw适配记录
移动端vw适配记录
2022-08-10 03:41:00 【TangAcrab】
1、安装postcss-px-to-viewport插件;
2、项目下新建postcss.config.js文件,修改内容如下:
module.exports = {
plugins:{
'postcss-px-to-viewport':{
unitToConvert:'px', // 要转换的单位
viewportWidth: 750, // 设计稿的尺寸
unitPrecision: 6, // 转换后的精度,即小数点位数
propList: ["*"], // 指定转换的css属性的单位,*代表全部css属性的单位都进行转换
viewportUnit: "vw", // 指定需要转换成的视窗单位,默认vw
fontViewportUnit: "vw", // 指定字体需要转换成的视窗单位
selectorBlackList: ["wrap"],
minPixelValue: 1, // 默认值1,小于或等于1px则不进行转换
mediaQuery: true, // 是否在媒体查询的css代码中也进行转换,默认false
replace: true, // 是否转换后直接更换属性值
exclude: [/node_modules/], // 设置忽略文件,用正则做目录名匹配
}
}
}
3、适配第三方ui库,解决项目设计稿尺寸与ui库基于尺寸不一致的问题; 例如 自己项目是750设计稿,使用基于375来开发的vant库。
动态设置视口宽度
const path = require('path');
module.exports = ({
webpack }) => {
const viewWidth = webpack.resourcePath.includes(path.join('node_modules', 'vant')) ? 375 : 750;
return {
plugins: {
autoprefixer: {
},
"postcss-px-to-viewport": {
unitToConvert: "px",
viewportWidth: viewWidth,
unitPrecision: 6,
propList: ["*"],
viewportUnit: "vw",
fontViewportUnit: "vw",
selectorBlackList: [],
minPixelValue: 1,
mediaQuery: true,
exclude: [],
landscape: false
}
}
}
}
关键判断
const viewWidth = webpack.resourcePath.includes(path.join('node_modules', 'vant')) ? 375 : 750
边栏推荐
猜你喜欢

数据切片问题

goland console shows overlapping problem solution

The same is a primary test, why does he pay 5,000 yuan more than me?

Small program subcontracting and subcontracting pre-download

ARP Spoofing - Tutorial Details

js原型和原型链以及原型继承

结构体的内存对齐问题

Do you know these basic types of software testing?

Dynamic Web Development Fundamentals

2022年危险化学品经营单位主要负责人题库及模拟考试
随机推荐
It's almost 35, still "did a little"?What happened to the test workers who had been in the industry for a few years?
ZZULIOJ:1016: 银行利率
TCP协议之《自动阻塞CORK控制》
1413.Minimum Value to Get Positive Step by Step Sum
【Verilog数字系统设计(夏雨闻)5-------模块的结构、数据类型、变量和基本运算符号1】
Neo4J 与 Cypher 查询语言基础
mediaserver创建
maya图片如何导入
The so-called software testing ability is actually these 5 points
2022华数杯思路分析
ES高亮显示语法
Small program subcontracting and subcontracting pre-download
c语言进阶篇:动态内存管理(相关函数、常见错误、笔试题)
创意优选技术
TCP协议之《ACK pingpong交互模式详解》
ZZULIOJ:1018: 奇数偶数
如何整合全流程数据,全面提升研发效能?|2分钟了解 ONES
转:不忧、不惧——成功领导者的自我成长和实现
order by注入与limit注入
郑州轻工业大学OJ合集(C语言)【正在整理】