自适应实用方法

网页设计最常用的单位是px,与之相对应的rem,能够对设置好的宽高进行自适应,所以在网页显示上面应该找准body上面设置字体等的px,以用来应付单位大小。
下面是根据屏幕宽度自适应设置字体大小的js

    (function() {
        setFontSize();
        function setFontSize() {
            var html = document.documentElement;
            var windowWidth = html.clientWidth;
            if(windowWidth <= 750) {
                html.style.fontSize = windowWidth / 7.5 + 'px';
            } else {
                html.style.fontSize = '100px';
            }
        };
        window.onresize = setFontSize;
    })();

猜你喜欢

转载自blog.csdn.net/fu415037685/article/details/80677443
今日推荐