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

fix: 微信浏览器字体适配rem #6

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion mobx/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,46 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" >
<title></title>
<script>
!function(x){function w(){var v,u,t,tes,s=x.document,r=s.documentElement,a=r.getBoundingClientRect().width;if(!v&&!u){var n=!!x.navigator.appVersion.match(/AppleWebKit.*Mobile.*/);v=x.devicePixelRatio;tes=x.devicePixelRatio;v=n?v:1,u=1/v}if(a>=640){r.style.fontSize="40px"}else{if(a<=320){r.style.fontSize="20px"}else{r.style.fontSize=a/320*20+"px"}}}x.addEventListener("resize",function(){w()});w()}(window);
!(function(x) {
function w() {
var v,
u,
t,
tes,
s = x.document,
r = s.documentElement,
a = r.getBoundingClientRect().width;
if (!v && !u) {
var n = !!x.navigator.appVersion.match(/AppleWebKit.*Mobile.*/);
v = x.devicePixelRatio;
tes = x.devicePixelRatio;
(v = n ? v : 1), (u = 1 / v);
}

// 微信字体大小适配处理
var divEle = document.createElement('div');
divEle.style = 'font-size: 20px';
document.body.appendChild(divEle);

var scaledFontSize = parseFloat(window.getComputedStyle(divEle, null).getPropertyValue('font-size'));
document.body.appendChild(divEle);
var scaleFactor = 20 / scaledFontSize;

if (a >= 640) {
r.style.fontSize = scaleFactor * 40 + 'px';
} else {
if (a <= 320) {
r.style.fontSize = scaleFactor * 20 + 'px';
} else {
r.style.fontSize = scaleFactor * (a / 320) * 20 + 'px';
}
}
}
x.addEventListener('resize', function() {
w();
});
w();
})(window);
</script>
</head>
<body>
Expand Down
41 changes: 40 additions & 1 deletion redux/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,46 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" >
<title></title>
<script>
!function(x){function w(){var v,u,t,tes,s=x.document,r=s.documentElement,a=r.getBoundingClientRect().width;if(!v&&!u){var n=!!x.navigator.appVersion.match(/AppleWebKit.*Mobile.*/);v=x.devicePixelRatio;tes=x.devicePixelRatio;v=n?v:1,u=1/v}if(a>=640){r.style.fontSize="40px"}else{if(a<=320){r.style.fontSize="20px"}else{r.style.fontSize=a/320*20+"px"}}}x.addEventListener("resize",function(){w()});w()}(window);
!(function(x) {
function w() {
var v,
u,
t,
tes,
s = x.document,
r = s.documentElement,
a = r.getBoundingClientRect().width;
if (!v && !u) {
var n = !!x.navigator.appVersion.match(/AppleWebKit.*Mobile.*/);
v = x.devicePixelRatio;
tes = x.devicePixelRatio;
(v = n ? v : 1), (u = 1 / v);
}

// 微信字体大小适配处理
var divEle = document.createElement('div');
divEle.style = 'font-size: 20px';
document.body.appendChild(divEle);

var scaledFontSize = parseFloat(window.getComputedStyle(divEle, null).getPropertyValue('font-size'));
document.body.appendChild(divEle);
var scaleFactor = 20 / scaledFontSize;

if (a >= 640) {
r.style.fontSize = scaleFactor * 40 + 'px';
} else {
if (a <= 320) {
r.style.fontSize = scaleFactor * 20 + 'px';
} else {
r.style.fontSize = scaleFactor * (a / 320) * 20 + 'px';
}
}
}
x.addEventListener('resize', function() {
w();
});
w();
})(window);
</script>
</head>
<body>
Expand Down
41 changes: 40 additions & 1 deletion wxcloud/client/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,46 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" >
<title></title>
<script>
!function(x){function w(){var v,u,t,tes,s=x.document,r=s.documentElement,a=r.getBoundingClientRect().width;if(!v&&!u){var n=!!x.navigator.appVersion.match(/AppleWebKit.*Mobile.*/);v=x.devicePixelRatio;tes=x.devicePixelRatio;v=n?v:1,u=1/v}if(a>=640){r.style.fontSize="40px"}else{if(a<=320){r.style.fontSize="20px"}else{r.style.fontSize=a/320*20+"px"}}}x.addEventListener("resize",function(){w()});w()}(window);
!(function(x) {
function w() {
var v,
u,
t,
tes,
s = x.document,
r = s.documentElement,
a = r.getBoundingClientRect().width;
if (!v && !u) {
var n = !!x.navigator.appVersion.match(/AppleWebKit.*Mobile.*/);
v = x.devicePixelRatio;
tes = x.devicePixelRatio;
(v = n ? v : 1), (u = 1 / v);
}

// 微信字体大小适配处理
var divEle = document.createElement('div');
divEle.style = 'font-size: 20px';
document.body.appendChild(divEle);

var scaledFontSize = parseFloat(window.getComputedStyle(divEle, null).getPropertyValue('font-size'));
document.body.appendChild(divEle);
var scaleFactor = 20 / scaledFontSize;

if (a >= 640) {
r.style.fontSize = scaleFactor * 40 + 'px';
} else {
if (a <= 320) {
r.style.fontSize = scaleFactor * 20 + 'px';
} else {
r.style.fontSize = scaleFactor * (a / 320) * 20 + 'px';
}
}
}
x.addEventListener('resize', function() {
w();
});
w();
})(window);
</script>
</head>
<body>
Expand Down