当前位置:网站首页>移动端像素适配方案
移动端像素适配方案
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
边栏推荐
- 谷歌浏览器实现视频播放加速功能
- Look! Internet, e-commerce offline big data analysis best practice! (Internet disk link attached)
- Interviewer: how about shardingsphere
- Diamond standard
- Using an example to understand the underlying processing mechanism of JS function
- ERD-ONLINE 免费在线数据库建模工具
- ORA-02292: 违反完整约束条件 (MIDBJDEV2.SYS_C0020757) - 已找到子记录
- Contract trading system development | construction of smart contract trading platform
- git远程库回退指定版本
- Axios learning notes (2): easy to understand the use of XHR and how to package simple Axios
猜你喜欢
Event monitoring problem
Stickinengine architecture 12 communication protocol
Introduction to the development of small game cloud
With this artifact, quickly say goodbye to spam messages
2020-09-04:函数调用约定了解么?
Why is the LS command stuck when there are too many files?
Interviewer: how about shardingsphere
迅为-iMX6ULL开发板上配置AP热点
Zero basis to build a web search engine of its own
What kind of music do you need to make for a complete game?
随机推荐
C language I blog assignment 03
打工人好物——磨炼钢铁意志就要这样高效的电脑
Introduction to Huawei cloud micro certification examination
How to start the hidden preferences in coda 2 on the terminal?
2020-09-04:函数调用约定了解么?
超高频RFID医疗血液管理系统应用
实用工具类函数(持续更新)
Flink's datasource Trilogy: direct API
Code generator plug-in and creator preform file analysis
[byte jumps, autumn recruitment Posts open] ohayoo! Don't leave after school, I want to ask you to play games!!!
Why is the LS command stuck when there are too many files?
STM32F030C6T6兼容替换MM32SPIN05PF
代码重构之法——方法重构分析
How much disk space does a file of 1 byte actually occupy
Using iceberg on kubernetes to create a new generation of cloud original data Lake
Open source a set of minimalist front and rear end separation project scaffold
Erd-online free online database modeling tool
Novice guidance and event management system in game development
Call analysis of start method in JNI thread and callback analysis of run method
Understanding formatting principles