移動端fontsize被瀏覽器自動放大導致rem自適應出問題

來源:互聯網
上載者:User

標籤:boosting   技術分享   iss   nbsp   pre   自動   元素   etc   ges   

最近寫移動端發現,當我用rem給html根項目一個指定的比例值時候,但會被webview的內建瀏覽給加一層過濾將其值放大

 

最終會影響rem的布局。最終在網上查了很久一篇文章寫font boosting的跟我的情況很相似。https://github.com/jin5354/404forest/issues/33。

於是按著他的方案去解決,然而並沒有用。

$(function(){
$(window).resize(infinite);
function infinite() {
var $html = $(‘html‘);
var htmlWidth =$html.width();
var html_fontsize = 28.8 / 720 * htmlWidth;
$html.css({
"font-size" : 28.8 / 720 * htmlWidth + "px"
});
if(html_fontsize == parseInt(getComputedStyle($html[0]).fontSize)){
return;
}
else {
var t_fs = html_fontsize/(parseInt(getComputedStyle($html[0]).fontSize)/html_fontsize);
$html.css({
"font-size" :t_fs+‘px‘
});
}
}infinite();
});
於是我寫了方法,來找到真實的fontsize。寫按著正常寫fontsize加到html上,然後根據瀏覽器擴大的比例。在計算出,真正需要寫多少fontsize經過放大後才能得到的你想要的computed的值。

移動端fontsize被瀏覽器自動放大導致rem自適應出問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.