根据窗口大小动态设置字体大小

2019-10-16  本文已影响0人  fisher爱吃鱼
<script>
    function adjustFontSize() {
        let deviceWidth = document.documentElement.clientWidth || window.innerWidth
        let rootFontSize = deviceWidth / 19.2
        document.querySelector('html').style.fontSize = rootFontSize + 'px'
    }
    adjustFontSize()
    
    window.addEventListner('resize', function () {
        adjustFontSize()
    })
</script>
上一篇 下一篇

猜你喜欢

热点阅读