rem单位的计算问题
移动端开发要对各种手机屏幕尺寸做到适配,此时最合适的就要数rem单位,以iphone6手机屏幕为标准,适配其他手机屏幕的js代码如下:
<script
type="text/javascript">
(function(){
var
html = document.documentElement;
var windowWidth =
window.screen.width;
var dpr =
window.devicePixelRatio;
if (window.devicePixelRatio >=
1.5) {
dpr = 2;
}
//设置data-dpi属性,留作的css hack之用
html.setAttribute('data-dpr',
dpr);
html.style.fontSize =
html.clientWidth /
7.5 + 'px';
})();
</script>