一
<script>
(function (doc, win) {
var docEl = doc.documentElement,
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
recalc = function () {
var clientWidth = docEl.clientWidth;
if (!clientWidth) return;
docEl.style.fontSize = 20 * (clientWidth / 320) + 'px';
};
if (!doc.addEventListener) return;
win.addEventListener(resizeEvt, recalc, false);
doc.addEventListener('DOMContentLoaded', recalc, false);
})(document, window);
</script>
二
<script>
var scale = $('body').width() / 640;
$('html').css('font-size', 100 * scale + 'px');
</script>
三(使用过的)
<script>
var fontSize = 100;
var elm = document.documentElement;
elm.style.fontSize = fontSize * (elm.clientWidth/320) + 'px';
</script>
网友评论