当前位置:网站首页>移动端像素适配方案
移动端像素适配方案
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
边栏推荐
- Contract trading system development | construction of smart contract trading platform
- The essence of transaction and the principle of deadlock
- 小熊派开发板实践:智慧路灯沙箱实验之真实设备接入
- C and C / C + + mixed programming series 5 - GC collaboration of memory management
- [forward] how to view UserData in Lua
- 轻量型 GPU 应用首选 京东智联云推出 NVIDIA vGPU 实例
- An article will take you to understand CSS3 fillet knowledge
- Metersphere developer's Manual
- Small program introduction to proficient (2): understand the four important files of small program development
- ES6 learning notes (2): teach you to play with class inheritance and class objects
猜你喜欢
2020-09-09:裸写算法:两个线程轮流打印数字1-100。
行为型模式之解释器模式
Flink's datasource Trilogy: direct API
ado.net and asp.net The relationship between
迅为iMX6开发板-设备树内核-menuconfig的使用
2020-08-19:TCP是通过什么机制保障可靠性的?
C calls SendMessage to refresh the taskbar icon (the icon does not disappear at the end of forcing)
统计项目代码行数
Kubernetes and OAM to build a unified, standardized application management platform knowledge! (Internet disk link attached)
EOS founder BM: what's the difference between UE, UBI and URI?
随机推荐
谷歌浏览器实现视频播放加速功能
【涂鸦物联网足迹】涂鸦云平台全景介绍
To teach you to easily understand the basic usage of Vue codemirror: mainly to achieve code editing, verification prompt, code formatting
Basic usage of Vue codemirror: search function, code folding function, get editor value and verify in time
递归、回溯算法常用数学基础公式
Helping financial technology innovation and development, atfx is at the forefront of the industry
How does filecoin's economic model and future value support the price of fil currency breaking through thousands
细数软件工程----各阶段必不可少的那些图
Metersphere developer's Manual
2020-08-29:进程线程的区别,除了包含关系之外的一些区别,底层详细信息?
Those who have worked in China for six years and a million annual salary want to share these four points with you
How to prepare for the system design interview
Summary of front-end interview questions (C, s, s) that front-end engineers need to understand (2)
What grammar is it? ]
window系统 本机查找端口号占用方法
2020-08-19:TCP是通过什么机制保障可靠性的?
Open source a set of minimalist front and rear end separation project scaffold
Method of code refactoring -- Analysis of method refactoring
Application insights application insights use application maps to build request link views
Look! Internet, e-commerce offline big data analysis best practice! (Internet disk link attached)