随着页面宽度动态设置REM默认值

111 阅读1分钟
$(document).ready(function () {
    if ($(window).width() <= 600) {
        $("html").css({
            fontSize: 12
        })
    } else if ($(window).width() > 600 && $(window).width() <= 900) {
        $("html").css({
            fontSize: 16
        })
    } else if ($(window).width() > 900 && $(window).width() <= 1200) {
        $("html").css({
            fontSize: 20
        })
    } else if ($(window).width() > 1200 && $(window).width() <= 1500) {
        $("html").css({
            fontSize: 24
        })
    } else if ($(window).width() > 1500) {
        $("html").css({
            fontSize: 28
        })
    }
    $(window).resize(function () {
        if ($(window).width() <= 600) {
            $("html").css({
                fontSize: 12
            })
        } else if ($(window).width() > 600 && $(window).width() <= 900) {
            $("html").css({
                fontSize: 16
            })
        } else if ($(window).width() > 900 && $(window).width() <= 1200) {
            $("html").css({
                fontSize: 20
            })
        } else if ($(window).width() > 1200 && $(window).width() <= 1500) {
            $("html").css({
                fontSize: 24
            })
        } else if ($(window).width() > 1500) {
            $("html").css({
                fontSize: 28
            })
        }
    });
});

不一定是最好的忘大神修改