-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
111 lines (100 loc) · 2.84 KB
/
index.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no" />
<title>H5强制竖屏(2019-3-29)</title>
<style type="text/css">
* {
margin: 0;
padding: 0;
}
@media screen and (orientation: portrait) {
html,
body {
width: 100%;
height: 100%;
}
#print {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
overflow: hidden;
background: url(img/login_bg.jpg) no-repeat;
background-size: cover;
}
}
@media screen and (orientation: landscape) {
html,
body {
width: 100%;
height: 100%;
}
#print {
position: absolute;
background: url(img/login_bg.jpg) no-repeat;
background-size: cover;
}
}
</style>
</head>
<body>
<div id="print">
</div>
<script>
//初始化
var width = document.documentElement.clientWidth;
var height = document.documentElement.clientHeight;
var print = document.getElementById("print");
if (width <= height) {
console.log("初始化竖屏");
console.log(width + " " + height);
print.style.width = width + "px";
print.style.height = height + "px";
print.style.top = "0px";
print.style.left = "0px";
print.style.transform = "none";
print.style.transformOrigin = "50% 50%";
}else{
console.log("初始化横屏");
print.style.width = height + "px";
print.style.height = width + "px";
print.style.top = (height - width) / 2 + "px";
print.style.left = -(height - width) / 2 + "px";
print.style.transform = "rotate(90deg)";
print.style.transformOrigin = "50% 50%";
}
var evt = "onorientationchange" in window ? "orientationchange" : "resize";
window.addEventListener(evt, function() {
console.log(evt);
setTimeout(function() { //解决移动端300ms延迟问题(不是最好的方案) 最好的方案是使用FastClick
var width = document.documentElement.clientWidth;
var height = document.documentElement.clientHeight;
if (width > height) {
console.log("横");
console.log(width);
console.log(height);
print.style.width = height + "px";
print.style.height = width + "px";
print.style.top = (height - width) / 2 + "px";
print.style.left = -(height - width) / 2 + "px";
print.style.transform = "rotate(90deg)";
print.style.transformOrigin = "50% 50%";
} else {
console.log("竖")
console.log(width);
console.log(height);
print.style.width = width + "px";
print.style.height = height + "px";
print.style.top = "0px";
print.style.left = "0px";
print.style.transform = "none";
print.style.transformOrigin = "50% 50%";
}
}, 300);
}, false);
</script>
</body>
</html>