美文网首页
根据窗口大小动态设置字体大小

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

作者: fisher爱吃鱼 | 来源:发表于2019-10-16 10:23 被阅读0次
<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>

相关文章

网友评论

      本文标题:根据窗口大小动态设置字体大小

      本文链接:https://www.haomeiwen.com/subject/nceymctx.html