Comments (2)
对的,他的方案确实是没有把dpr考虑进去,并且没有解决手机1px问题。
可以参考一下我的解决方案。
(function(designSize) { //designSize为设计稿的尺寸(宽)
var doc = document,
docEl = doc.documentElement,
devWidth = docEl.clientWidth > 1080 ? 1080 : docEl.clientWidth,
dpr = devicePixelRatio || 1, //如果不支持devicePixelRatio则默认为1
scale = 1 / dpr,
width = dpr * devWidth,
document.querySelector('meta[name="viewport"]')
.setAttribute('content','width=' + width +
', initial-scale=' + scale +
', maximum-scale=' + scale +
', minimum-scale=' + scale +
', user-scalable=no');
docEl.style.fontSize = devWidth / (designSize / 100) * dpr + 'px';
})(750);
然后在写CSS的时候,按设计稿上的尺寸除以100就可以了。
from rem.
这个方案确实没处理dpr,1px的思路的单独判断加特别的样式控制。谢谢 @dayney 和 @2ue 的方案,学习了。
from rem.
Related Issues (16)
- 此方案字体大小可否直接使用rem单位? HOT 3
- 如果设计稿是750px的,adapt函数设置需要更改成(750,117.1875)吗 HOT 1
- html设定为固定的px,就不会随系统字体大小改变了,所以不明白方案3为什么是不行的? HOT 1
- 关于18px下分析的几个值的问题 HOT 1
- 手机 4k 屏幕下 如何适配 HOT 1
- 关于竖屏横屏的问题
- chrome下手机测试失效。 HOT 3
- 设计稿如果是750 HOT 3
- 目前成熟方案:flexible HOT 2
- .0.0.
- 关于方案3的一个问题 HOT 8
- 在谷歌浏览器上模拟手机调试字体不能自动变化 要手动刷新 是什么原因 HOT 3
- 关于在ie中的一些问题 HOT 2
- 关于4.1的问题 HOT 14
- 求解释rem2px的值 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rem.