rem.js 373 B

123456789101112131415
  1. /** 设置 rem 函数 */
  2. function setRem() {
  3. console.log(222223)
  4. const htmlWidth =
  5. document.documentElement.clientWidth || document.body.clientWidth
  6. const htmlDom = document.getElementsByTagName('html')[0]
  7. console.log(htmlWidth, htmlDom.style.fontSize)
  8. htmlDom.style.fontSize = htmlWidth / 100 + 'px'
  9. }
  10. setRem()
  11. window.onresize = function () {
  12. setRem()
  13. }