<!doctype html>
<html>
<head>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,minimum-scale=1,maximum-scale=1,user-scalable=no">
<meta name="format-detection" content="telephone=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<script type="text/javascript" src="http://wap.tszyzx.com/js/jquery-1.10.1.min.js"></script>
<script>
(function (doc, win) {
var docEl = doc.documentElement,
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
recalc = function () {
var clientWidth = docEl.clientWidth;
if (!clientWidth) return;
if(clientWidth>=640){
docEl.style.fontSize = '100px';
}else{
docEl.style.fontSize = 100 * (clientWidth / 640) + 'px';
}
};
if (!doc.addEventListener) return;
win.addEventListener(resizeEvt, recalc, false);
doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);
</script>
<title>无标题文档</title>
<style>
html{ font-size:100px;}
body{ margin:0px; padding:0px;}
</style>
</head>
<body>
<div id="id" style="background:url(images/mopening_05.jpg) no-repeat; background-size:100%; height:4.94rem; border:solid 1px #f90;"></div>
</body>
</html>
<script>
var div=document.getElementById("id");
alert(window.getComputedStyle(div).fontSize);
</script>
特别注意上面的定义是640,那么图片的大小也应该是640.图片的实际px和这里要一致。
美工给我的是950,那我也只有改成950了。测试正常
链接:https://pan.baidu.com/s/1JRVRYR-Z14chEBZbQ9oHIg
提取码:ib2f
<!doctype html>
<html>
<head>
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,minimum-scale=1,maximum-scale=1,user-scalable=no">
<meta name="format-detection" content="telephone=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<script type="text/javascript" src="http://wap.tszyzx.com/js/jquery-1.10.1.min.js"></script>
<script>
(function (doc, win) {
var docEl = doc.documentElement,
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
recalc = function () {
var clientWidth = docEl.clientWidth;
if (!clientWidth) return;
if(clientWidth>=950){
docEl.style.fontSize = '100px';
}else{
docEl.style.fontSize = 100 * (clientWidth / 950) + 'px';
}
};
if (!doc.addEventListener) return;
win.addEventListener(resizeEvt, recalc, false);
doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);
</script>
<title>无标题文档</title>
<style>
body{ margin:0px; padding:0px;}
</style>
</head>
<body>
<div style="background:url(images/mopening_05.jpg) no-repeat; background-size:100%; height:4.94rem;"></div>
<div style="background:url(images/mopening_06.jpg) no-repeat; background-size:100%; height:6.31rem;"></div>
<div style="background:url(images/mopening_07.jpg) no-repeat; background-size:100%; height:0.01rem;"></div>
<div style="background:url(images/mopening_08.jpg) no-repeat; background-size:100%; height:8.01rem;"></div>
<div style="background:url(images/mopening_09.jpg) no-repeat; background-size:100%; height:8.02rem;"></div>
</body>
</html>