有时候在移动端布局的时候,我们想让一个指定的px为所有设备的总宽度下面这个代码就可以使把所有设备的总宽度设置为360px
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>数据详情</title>
</head>
<body>
<div id="app"></div>
</body>
<script>
/* 设置浏览器逻辑宽度的像素为定值 */
//把360像素设为浏览器的宽度
(function(document, window, width) {
var scale = window.screen.width / width,
viewPort = '<meta name = "viewport" content = "';
viewPort += 'target-densitydpi = device-dpi, width = ' + width + ', initial-scale = ' + scale;
viewPort += ',minimum-scale = ' + scale + ', maximum-scale = ' + scale + ', user-scalable = no';
document.write(viewPort + '">');
})(document, window, 360);
</script>
</html>