-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path移动端适配.html
68 lines (62 loc) · 2.38 KB
/
移动端适配.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes"><!-- 删除苹果默认的工具栏和菜单栏 -->
<meta name="apple-mobile-web-app-status-bar-style" content="black"><!-- 设置苹果工具栏颜色 -->
<meta name="format-detection" content="telephone=no, email=no"><!-- 忽略页面中的数字识别为电话,忽略email识别 -->
<meta name="keywords" content="">
<meta name="description" content="">
<title>移动端适配</title>
<style>
html{
font-size: calc( 100 * (100vw / 640));
-webkit-tap-highlight-color:rgba(0,0,0,0);
-webkit-text-size-adjust: 100%;
-ms-text-size-adjust: 100%;
}
@media screen and (min-width: 640px){
html{font-size: 100px;}
}
@media screen and (max-width: 320px){
html{font-size: 50px;}
}
</style>
</head>
<body>
<script>
setRem();
window.addEventListener("orientationchange", setRem);
window.addEventListener("resize", setRem);
function setRem() {
var html = document.querySelector("html");
var width = html.getBoundingClientRect().width;
html.style.fontSize = width / 15 + "px";
//750的效果图 /15 1rem == 50
//640的效果图 可以除以16 1rem==40
}
/*小杰锅锅版*/
(function (doc, win) {
var docEl = doc.documentElement,
resizeEvt = 'orientationchange' in window ? 'orientationchange' : 'resize',
recalc = function () {
var clientWidth = docEl.clientWidth;
if (!clientWidth) return;
if (clientWidth >= 750) {
docEl.style.fontSize = '100px';
} else {
docEl.style.fontSize = 100 * (clientWidth / 750) + 'px';
}
};
if (!doc.addEventListener) return;
win.addEventListener(resizeEvt, recalc, false);
doc.addEventListener('DOMContentLoaded', recalc, false);
recalc();
})(document, window);
</script>
</body>
</html>