h5px 转rem

 <script type="text/javascript">
    // px转rem
        var rootResize = function() {
            var baseFontSize = 100;
            var baseWidth = 750;
            var minWidth = 320;
            var clientWidth = document.documentElement.clientWidth || window.innerWidth;
            var innerWidth = Math.max(Math.min(clientWidth, baseWidth), minWidth);

            var rem = clientWidth / (baseWidth / baseFontSize);
            if (innerWidth == 750 || innerWidth == 320) {
                rem = innerWidth / (baseWidth / baseFontSize)
            }

            document.querySelector('html').style.fontSize = rem + 'px';
        };
        rootResize();
        window.οnresize = function() {
            rootResize()
        };

    </script>

css:

html {
    font-size: 100px;
    font-family:PingFang SC;
    /*line-height: .45rem;*/
    font-weight:400;
    padding: 0;
    margin: 0;
}
 

猜你喜欢

转载自blog.csdn.net/qq_43671996/article/details/102696955