Home >Web Front-end >JS Tutorial >Application of rem layout in JavaScript in react_javascript skills
I shared a react project with you earlier (http://www.jb51.net/article/76085.htm). This time I have made some improvements to the project, adding rem layout and Optimization of iscroll on Android.
Project code, welcome to fork and star, online preview
REM layout example code
var fontSizeInit = function() { var doc = document.documentElement, cli = doc.clientWidth; cli&&(cli/=320,2<cli&&(cli=2),doc.style.fontSize=16*cli+"px"); } fontSizeInit(); window.addEventListener('resize', function() { fontSizeInit(); });
sass:
$baseFontSize:16px !default; // pixels to rems @function pxToRem($px) { @return $px / $baseFontSize * 1rem; } html { font-size: $baseFontSize; -ms-touch-action: none; }