-
Notifications
You must be signed in to change notification settings - Fork 27
/
common.js
55 lines (43 loc) · 1.51 KB
/
common.js
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
/////////填写你的apikey
const APIKEY = 'YOUR APIKEY';
const APISERET = 'YOUR APISERET';
//////////////////
//界面跳转
function navigateTo(page) {
window.location.href = page + '.html';
}
//判断是否是手机
function isMobile() {
const userAgentInfo = navigator.userAgent;
const mobileAgents = ['Android', 'iPhone', 'SymbianOS', 'Windows Phone', 'iPod']; // iPad
let mobile_flag = false;
// 根据userAgent判断是否是手机
for (let v = 0; v < mobileAgents.length; v++) {
if (userAgentInfo.indexOf(mobileAgents[v]) > 0) {
mobile_flag = true;
break;
}
}
const screen_width = window.screen.width;
const screen_height = window.screen.height;
// 根据屏幕分辨率判断是否是手机
if (screen_width < 500 && screen_height < 800) {
mobile_flag = true;
}
return mobile_flag;
}
//设置界面大小
function resetContainer() {
const screenH = document.documentElement.clientHeight || document.body.clientHeight;
const screenW = document.documentElement.clientWidth || document.body.clientWidth;
const container = document.getElementsByClassName('container')[0];
const isMb = isMobile();
console.log(`isMobole ----` + isMb);
if (isMb == false) {// pc or ipad
container.style.width = "375px";
container.style.height = '667px';
container.style.top = ((screenH - 667) / 2) + "px";
console.log(container.style.top);
container.backgroundColor = 'red';
}
}