当前位置:网站首页>移动端像素适配方案
移动端像素适配方案
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
边栏推荐
- 大数据处理黑科技:揭秘PB级数仓GaussDB(DWS) 并行计算技术
- mongo 用户权限 登录指令
- 2020-09-09:裸写算法:两个线程轮流打印数字1-100。
- 打工人好物——磨炼钢铁意志就要这样高效的电脑
- 2020-08-29:进程线程的区别,除了包含关系之外的一些区别,底层详细信息?
- Unity performance optimization
- Metersphere developer's Manual
- Event monitoring problem
- An article taught you to download cool dog music using Python web crawler
- 轻量型 GPU 应用首选 京东智联云推出 NVIDIA vGPU 实例
猜你喜欢
GitHub: the foundation of the front end
Zero basis to build a web search engine of its own
Cloudquery v1.2.0 release
2020-09-04:函数调用约定了解么?
Diamond standard
What grammar is it? ]
打工人好物——磨炼钢铁意志就要这样高效的电脑
2020-08-17:详细说下数据倾斜怎么解决?
ES6 learning notes (4): easy to understand the new grammar of ES6
ES6 learning notes (2): teach you to play with class inheritance and class objects
随机推荐
The Interpreter pattern of behavior pattern
2020 database technology conference helps technology upgrade
ES6 learning notes (3): teach you to use js object-oriented thinking to realize the function of adding, deleting, modifying and checking tab column
Contract trading system development | construction of smart contract trading platform
Using iceberg on kubernetes to create a new generation of cloud original data Lake
ES6 learning notes (5): easy to understand ES6's built-in extension objects
An article takes you to understand CSS pagination examples
细数软件工程----各阶段必不可少的那些图
【涂鸦物联网足迹】涂鸦云平台全景介绍
2020-08-14:数据任务的执行引擎用的哪些?
Common syntax corresponding table of mongodb and SQL
Axios learning notes (2): easy to understand the use of XHR and how to package simple Axios
Interviewer: how about shardingsphere
mongo 用户权限 登录指令
What grammar is it? ]
The 4th China BIM (digital construction) manager Summit Forum will be held in Hangzhou in 2020
ERD-ONLINE 免费在线数据库建模工具
STM32F030K6T6兼容替换灵动MM32F031K6T6
Using an example to understand the underlying processing mechanism of JS function
The legality of IPFs / filecoin: protecting personal privacy from disclosure