当前位置:网站首页>移动端像素适配方案
移动端像素适配方案
2020-11-06 22:11:00 【进击的前端】
rem
1. 在 public文件夹的公共html添加配置
原理:在文件的根目录生成添加font-size
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Web site created using create-react-app" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>React App</title>
<script>
(function (w) {
var doc = w.document;
var docEl = doc.documentElement;
var timer;
function refersh() {
var width = docEl.getBoundingClientRect().width;
if (width > 750) {
width = 750;
}
var rem = width / 7.5;
docEl.style.fontSize = rem + "px";
}
w.addEventListener('resize', function () {
timer && clearTimeout(timer);
timer = setTimeout(refersh, 400)
})
w.addEventListener('pageshow', function () {
timer && clearTimeout(timer);
timer = setTimeout(refersh, 400)
})
})(window)
</script>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
</body>
</html>
2.
vm
vue-cli 自动匹配vm, 使用第三方依赖包
postcss-px-to-viewport 在vue.config.js文件中配置:
const pxtovw = require('postcss-px-to-viewport')
module.exports = {
css: {
loaderOptions: {
css: {
// 这里的选项会传递给 css-loader
},
postcss: {
// 这里的选项会传递给 postcss-loader
plugins: [
new pxtovw({
unitToConvert: 'px',
viewportWidth: 375,
unitPrecision: 5,
propList: ['*'],
viewportUnit: 'vw',
fontViewportUnit: 'vw',
selectorBlackList: [],
minPixelValue: 1,
mediaQuery: false,
replace: true,
exclude: [/node_modules/]
})
]
}
}
}
}
版权声明
本文为[进击的前端]所创,转载请带上原文链接,感谢
https://my.oschina.net/u/4618999/blog/4706901
边栏推荐
- mongo 用户权限 登录指令
- How to play sortable JS vuedraggable to realize nested drag function of forms
- Tron smart wallet PHP development kit [zero TRX collection]
- An article takes you to understand CSS3 picture border
- Summary of front-end interview questions (C, s, s) that front-end engineers need to understand (2)
- How much disk space does a new empty file take?
- How to prepare for the system design interview
- An article will take you to understand CSS3 fillet knowledge
- 2020-08-15:什么情况下数据任务需要优化?
- What the hell is fastthreadlocal? The existence of ThreadLocal!!
猜你喜欢

大数据处理黑科技:揭秘PB级数仓GaussDB(DWS) 并行计算技术

行为型模式之备忘录模式

ES6 learning notes (3): teach you to use js object-oriented thinking to realize the function of adding, deleting, modifying and checking tab column

Python basic data type -- tuple analysis

ado.net和asp.net的关系

STM32F030K6T6兼容替换灵动MM32F031K6T6

The role of theme music in games

ES6 learning notes (5): easy to understand ES6's built-in extension objects

ES6 learning notes (4): easy to understand the new grammar of ES6

Multi robot market share solution
随机推荐
How to manage the authority of database account?
The essence of transaction and the principle of deadlock
Understanding formatting principles
Zero basis to build a web search engine of its own
The isolation level of transaction and its problems
Interviewer: how about shardingsphere
2020 database technology conference helps technology upgrade
非易失性MRAM存储器应用于各级高速缓存
轻量型 GPU 应用首选 京东智联云推出 NVIDIA vGPU 实例
Summary of common SQL statements
JVM memory allocation - xms128m - xmx512m - XX: permsize = 128M - XX: maxpermsize = 512M
[elastic search engine]
How to start the hidden preferences in coda 2 on the terminal?
迅为iMX6开发板-设备树内核-menuconfig的使用
es创建新的索引库并拷贝旧的索引库 实践亲测有效!
STM32F030C6T6兼容替换MM32SPIN05PF
Metersphere developer's Manual
C and C / C + + mixed programming series 5 - GC collaboration of memory management
STM32F030F4P6兼容灵动微MM32F031F4P6
ES6 learning notes (4): easy to understand the new grammar of ES6