当前位置:网站首页>移动端像素适配方案
移动端像素适配方案
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
边栏推荐
- An article will take you to understand SVG gradient knowledge
- window系统 本机查找端口号占用方法
- Basic usage of Vue codemirror: search function, code folding function, get editor value and verify in time
- An article will introduce you to CSS3 background knowledge
- 2020-08-15:什么情况下数据任务需要优化?
- C and C / C + + mixed programming series 5 - GC collaboration of memory management
- Exclusive interview with Alibaba cloud database for 2020 PostgreSQL Asia Conference: Zeng Wenjing
- Visual rolling [contrast beauty]
- 2020-09-04:函数调用约定了解么?
- CloudQuery V1.2.0 版本发布
猜你喜欢

【涂鸦物联网足迹】物联网基础介绍篇

An article takes you to understand CSS gradient knowledge

Epu360: all the H5 templates you want are here, e-book, big turntable, red envelope rain, questionnaire survey

An article will introduce you to CSS3 background knowledge

Summary of front-end interview questions (C, s, s) that front-end engineers need to understand (2)
![[byte jumps, autumn recruitment Posts open] ohayoo! Don't leave after school, I want to ask you to play games!!!](/img/3b/00bc81122d330c9d59909994e61027.jpg)
[byte jumps, autumn recruitment Posts open] ohayoo! Don't leave after school, I want to ask you to play games!!!

An article taught you to download cool dog music using Python web crawler

jenkins安装部署过程简记

This project allows you to quickly learn about a programming language in a few minutes

超高频RFID医疗血液管理系统应用
随机推荐
Zero basis to build a web search engine of its own
The legality of IPFs / filecoin: protecting personal privacy from disclosure
The isolation level of transaction and its problems
Call analysis of start method in JNI thread and callback analysis of run method
Exclusive interview of guests at | 2020 PostgreSQL Asia Conference: Wang Tao
Axios learning notes (2): easy to understand the use of XHR and how to package simple Axios
list转换map(根据key来拆分list,相同key的value为一个list)
ORA-02292: 违反完整约束条件 (MIDBJDEV2.SYS_C0020757) - 已找到子记录
Open source a set of minimalist front and rear end separation project scaffold
大数据处理黑科技:揭秘PB级数仓GaussDB(DWS) 并行计算技术
How to make characters move
【涂鸦物联网足迹】物联网基础介绍篇
image operating system windows cannot be used on this platform
ado.net和asp.net的关系
To solve the problem that the data interface is not updated after WPF binding set
小熊派开发板实践:智慧路灯沙箱实验之真实设备接入
How to prepare for the system design interview
Python basic variable type -- list analysis
Python basic data type -- tuple analysis
Cloudquery v1.2.0 release