Mobile terminal screen adaptation - simple adaptation scheme

html font size change as the screen size is changed, the package function is as follows:

 

(function(){
    'use strict';
    
    setRemUnit();
    window.addEventListener('resize',setRemUnit);
    function setRemUnit(){
        var docEl = document.documentElement;
        var ratio = 18.75;
        var viewWidth = docEl.getBoundingClientRect().width || window.innerWidth;
        docEl.style.fontSize = viewWidth / ratio + 'px';
    }
})();

 

Guess you like

Origin www.cnblogs.com/rickdiculous/p/11564437.html