页面渲染后,除了用 document.body.clientWidth 获取屏幕网页可见区域宽高…还可以尝试使用getComputedStyle,此属性能获取DOM对应的CSS属性值。
//给html重置字体大小
setFontSzie() {
if (!this.initSize) {
this.initSize = window.getComputedStyle(document.body).getPropertyValue("font-size");
//getPropertyValue获取需要的属性值
}
var fontSize = parseInt(this.initSize) * 1.6;
document.getElementsByTagName("html")[0].setAttribute("style", "font-size:" + fontSize + "px !important");
}