1. 程式人生 > >動態改變 rem 大小

動態改變 rem 大小

<script>
    !function () {
        var html = document.documentElement;
        var setFontSize = function () {
            html.style.fontSize = html.offsetWidth / 6.4 + 'px';
        };
        var timer;
        var setDelay = function () {
            return clearTimeout(timer), (timer = setTimeout(setFontSize, 150));
        }
        window.addEventListener('pageshow', function (evt) {
            return evt.persisted && setDelay();
        });
        window.addEventListener('resize', setDelay);
        setFontSize();
    }();
</script>