px 변환rem 자동 적응 핸드폰 스타일

1546 단어
/ px rem
var IntervalId  = 0;
window.onload = function() {
    IntervalId = self.setInterval("RemCount()", 100);
};
function RemCount() {
    var ClientWidth = document.documentElement.clientWidth || document.body.clientWidth;
    if (ClientWidth < 10) {
        return;
    }
    var viewport = document.querySelector("meta[name=viewport]");
    if (window.devicePixelRatio == 1) {
        viewport.setAttribute('content', 'width=device-width,initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no');
    }
    if (window.devicePixelRatio == 2) {
        viewport.setAttribute('content', 'width=device-width,initial-scale=0.5, maximum-scale=0.5, minimum-scale=0.5, user-scalable=no');
    }
    if (window.devicePixelRatio == 3) {
        viewport.setAttribute('content', 'width=device-width,initial-scale=0.3333333333333333, maximum-scale=0.3333333333333333, minimum-scale=0.3333333333333333, user-scalable=no');
    }
    // 1rem = 10rem  1:16, 1:16, ( )
    var ClientWidth = document.documentElement.clientWidth || document.body.clientWidth;
    if (ClientWidth > 0) {
        localStorage.ClientWidth = ClientWidth;
    } else {
        ClientWidth = localStorage.ClientWidth;
    }
    document.documentElement.style.fontSize = ClientWidth / 7.5 + 'px';
    console.log("PHP , rem :" + ClientWidth + " / " + (ClientWidth/7.5));
    if (ClientWidth > 0) {
        window.clearInterval(IntervalId);
    }
}

좋은 웹페이지 즐겨찾기