文字超出 ,字体缩小以显示完整

window.onload = function () {
      var divHeight = document.getElementById('chenqi').clientWidth//获取容器固定宽度
      var scrollWidth = document.getElementById('chenqi').scrollWidth//获取容器内容超出总宽度
      console.log('chenqi',divHeight)
      console.log('chenqi',scrollWidth)
      console.log('chenqi')
      // debugger
      // var i = 1
      while (scrollWidth > divHeight) {
        document.getElementById('chenqi').style.fontSize = 1 - i
        divHeight = document.getElementById('chenqi').clientWidth
        i++
      }
    }

  

posted @ 2021-09-13 17:19  吃鸡小能手  阅读(218)  评论(0编辑  收藏  举报