布局缩放

js设置浏览器缩放比例

 function matchWidth() {
    let doc = document;
    var docEl = doc.documentElement,resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
    recalc = function () {
        var clientWidth = docEl.clientWidth;
        if (!clientWidth) return;
        if (clientWidth >=1920) {
             docEl.style.fontSize = '100px';
        } else {
             docEl.style.fontSize = 100 * (clientWidth / 1920) + 'px';
        }
    };
    if (!doc.addEventListener) return;
    window.addEventListener(resizeEvt, recalc, false);
    doc.addEventListener('DOMContentLoaded', recalc, false);
 }
matchWidth()

 css设置缩放比例

@media screen and (min-width:1920px) {
    html{
        font-size: 100px;
    }
}
@media screen and (max-width:1920px) {
    html{
        font-size: 100px;
    }
}
@media screen and (max-width:1680px) {
    html{
        font-size:  87.5px;
    }
}
@media screen and (max-width:1440px) {
    html{
        font-size: 75px;
    }
}
@media screen and (max-width:1366px) {
    html{
        font-size: 71.1px;
    }
}
@media screen and (max-width:1280px) {
    html{
        font-size: 66.7px;
    }
}
@media screen and (max-width:1024px) {
    html{
        font-size: 53.3px;
    }
}

 注意,css设置的样式需要rem布局

猜你喜欢

转载自www.cnblogs.com/good-qinqin/p/10034061.html