visualization/js/myrem.js

19 lines
602 B
JavaScript
Raw Normal View History

2021-04-26 18:14:04 +08:00
// 实现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()
}
})()