第一種 自己寫個js 根據頁面寬度去計算字體大小
要吧頁面上的body的option 設置成0 防止頁面閃屏
window.addEventListener('DOMContentLoaded', function (){ var shuping = 'onorientationchange' in window ? 'orientationchange' : 'resize'; var timer = null; //設置字體 function setFontSize(){ var w = document.documentElement.clientWidth || document.body.clientWidth; document.documentElement.style.fontSize = 100*w/640 + 'px'; setTimeout(function(){ document.getElementsByTagName('body')[0].style.opacity = 1; },1000) } setFontSize(); window.addEventListener(shuping, function (){ clearTimeout(timer); timer = setTimeout(setFontSize, 300); }, false); }, false);
第二種 用hotcss.js
具體怎么使用請參考 https://github.com/imochen/hotcss
gulp 自動化工具 hotcss.rar
第三種 使用Flexible實現手淘H5頁面的終端適配
請參考 http://www.w3cplus.com/mobile/lib-flexible-for-html5-layout.html