visualization/js/myrem.js
jiutianzhiyu 49befa3980 提交
2021-04-26 18:14:04 +08:00

19 lines
602 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 实现rem适配
(function () {
var setFont = function () {
var html = document.documentElement
// 获取屏幕的宽度
var width = html.clientWidth
if (width < 1024) width = 1024
if (width > 1920) width = 1920
// 计算当前屏幕下一个rem所代表的px大小
var fontSize = width / 80 + 'px'
console.log(fontSize)
// 将字体大小赋值给htm根元素因为rem是参照html根元素的
html.style.fontSize = fontSize
}
setFont()
window.onresize = function () {
setFont()
}
})()