html5字体自适应
<script>
(function (doc, win) {
var docEle = doc.documentElement,
resizeEvent = 'orientationchange' in window ? 'orientationchange' : 'resize';
var recalCulate = function () {
var width = docEle.clientWidth;
docEle.style.fontSize = 100 * (width / 750) + 'px'; // 设计稿 750px
};
recalCulate();
if (!doc.addEventListener) return;
win.addEventListener(resizeEvent, recalCulate, false);
})(document, window);
</script>
eg. font-szie: 18px; 写成 font-size: 0.36rem;
本文来自博客园,作者:小虾米吖~,转载请注明原文链接:https://www.cnblogs.com/LindaBlog/p/14583390.html