Closed
Description
比如华为的某款老机型,因为他们算法的问题,设置的fontSize,不等于最终编译得到的
var $html = $('html');
var html = document.getElementsByTagName('html')[0];
alert(html.style.fontSize); // 36px 这说明 <html style="font-size:36px">
alert(window.getComputedStyle(html).fontSize); //31px
alert($html.css('font-size')); // 31px
根据实验,设置为42px的时候,华为会计算为36px
//这句话设置虽然可行,但是不知道什么原因会页面会闪一下,然后又还原回去
html.style.fontSize = '42px';
alert(window.getComputedStyle(html).fontSize); //36px
//jQuery的设置是有效的,并且页面不会闪回去
$html.attr('style', 'font-size:' + 42 + 'px!important;');
alert($html.css('font-size')); //36px
将上例改为,必须!important 才能让页面有效
html.setAttribute('style', 'font-size:42px!important'); //实验了html.style.fontSize = '42px!important' 都不行
Activity
[-]针对部分Android机型的rem解决方案[/-][+]针对部分Android机型的根px不等于设置的px,导致rem误差的解决方案[/+]fly-studio commentedon Nov 24, 2016
所以最终的设置JS代码为
设置循环100次跳出也是无奈之举,鬼晓得那个设备能不能设置到预定的值
mingelz commentedon Nov 24, 2016
看看是不是和 Font Boosting (amfe/article#10) 有关系
renyuns commentedon Mar 27, 2020
Android 实在是太坑爹了,各种厂商自己搞自己的