Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rem #3

Open
smallbore opened this issue Jun 20, 2017 · 0 comments
Open

rem #3

smallbore opened this issue Jun 20, 2017 · 0 comments

Comments

@smallbore
Copy link
Owner

smallbore commented Jun 20, 2017

1. js-改变根字号,px转rem
(function (doc, win) {
var docEl = doc.documentElement,
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
recalc = function () {
var clientWidth = docEl.clientWidth;
if(clientWidth > 640){
clientWidth = 640;
}
if (!clientWidth) return;
docEl.style.fontSize = 20 * (clientWidth / 320) + 'px';
};

if (!doc.addEventListener) return;
win.addEventListener(resizeEvt, recalc, false);
doc.addEventListener('DOMContentLoaded', recalc, false);

})(document, window);
2.css密集点查询 rem

html {
font-size: 62.5%
}
@media screen and (min-width: 320px) {
html {font-size: 14px;}
}

@media screen and (min-width: 360px) {
html {font-size: 16px;}
}

@media screen and (min-width: 400px) {
html {font-size: 18px;}
}

@media screen and (min-width: 440px) {
html {font-size: 20px;}
}

@media screen and (min-width: 480px) {
html {font-size: 22px;}
}

@media screen and (min-width: 640px) {
html {font-size: 28px;}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant