前端实时更改根目录font-size
- <script>
-
(function () {var clientwidth = document.documentElement.clientWidth || window.innerWidth;if (clientwidth>750) return// 在标准 375px 适配下,100px = 1rem;var basefontsize = 100;var basewidth = 375;var set = function () {var rem = 100;if (clientwidth != basewidth) {rem = Math.floor(clientwidth / basewidth * basefontsize);}document.querySelector('html').style.fontsize = rem + 'px';}set();window.addEventListener('resize', set);}());
- </script>
本人小白,各位想踏入前端的,我们可以一起学习,欢迎程序员大佬的指点