util.js
1.45 KB
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
;(function() {
window.exports.util = {
getClientHeight: function() {
return document.documentElement.clientHeight;
},
getClientWidth: function() {
return document.documentElement.clientWidth;
},
setWrapHeight: function(element, type) {
var height = 0;
height = this.getClientHeight();
if (type == "border") {
height = height - 70;
}
element.style.height = height+'px';
return height;
},
setBigImgSize: function(element, width, height) {
element.style.height = height+'px';
element.style.width = width+'px';
},
setBannerSize: function() {
var banner = document.querySelector('.banner');
var img = document.querySelector('.banner-img');
var height = this.setWrapHeight(banner, 'border'); //border: 页面上下模块边界,表示第一个和最后一个
var width = this.clientWidth || this.getClientWidth();
this.setBigImgSize(img, width, height);
},
setThemeSize: function() {
var themes = document.querySelectorAll('.theme');
for(var i=0; i<themes.length; i++) {
this.setWrapHeight(themes[i]);
}
},
isMacWebkit: function() {
return (navigator.userAgent.indexOf('Machintosh') !== -1 && navigator.userAgent.indexOf('Webkit') !== -1);
},
isFireFox: function() {
return navigator.userAgent.indexOf('Gecko') !== -1;
},
getEvent: function(event) {
return event || window.event;
},
getEventTarget: function(event) {
return event.target || event.scrElement;
}
}
})()