js rem的换算 适配各个屏幕

(function(){
			function computed(){
				let winW = document.documentElement.clientWidth,
					desW = 750,
					root = 100,
					ratio = winW / desW * root;
				if(winW > desW){
					document.documentElement.style.fontSize = root + 'px';
					return 
				}
				document.documentElement.style.fontSize = ratio + 'px';
			}
			computed();
			window.addEventListener('resize',computed);
		})();

  

posted @ 2021-01-28 13:51  酸suan  阅读(94)  评论(1编辑  收藏  举报