首页 > 其他分享 >rem 实现PC端字体适配

rem 实现PC端字体适配

时间:2022-09-19 18:14:07浏览次数:70  
标签:function 适配 PC let rem tid win refreshRem

新建rem.js

(function(win) {
    		var tid;
    		function refreshRem() {
    			let designSize = 1080; // 设计图尺寸
    			let html = document.documentElement;
    			let wW = html.clientWidth;// 窗口宽度
    			let rem = wW * 100 / designSize; 
    			document.documentElement.style.fontSize = rem + 'px';
    	    }
	     
	    win.addEventListener('resize', function() {
	    	clearTimeout(tid);
	    	tid = setTimeout(refreshRem, 300);
	    }, false);
	    win.addEventListener('pageshow', function(e) {
	    	if (e.persisted) {
	    		clearTimeout(tid);
	    		tid = setTimeout(refreshRem, 300);
	    	}
	    }, false);

	    refreshRem();

	})(window);

  main.js中引入即可

 

标签:function,适配,PC,let,rem,tid,win,refreshRem
From: https://www.cnblogs.com/-123456/p/16708552.html

相关文章