common.js
1.73 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
* @description: common js
* @author: lore-w
* @date: 2015-4-23
*/
var $ = require('jquery'),
swiper = require('swiper-mobile');
require('jgestures');
// 初始化页面
exports.init = function () {
// nav
var navSwiper = new swiper('.girl-nav',{
grabCursor: true,
slidesPerView: 'auto',
slideElement: 'li',
hashnav: true
});
// channel page banner
var channelSwiper = new swiper('.banner .swiper-container',{
loop: true,
pagination: '.pagination',
grabCursor: true,
paginationClickable: true,
autoplay: 5000,
slideElement: 'li'
});
// download app
var downBtn = $('.home-download').find('.down-btn');
if (downBtn.length > 0) {
if (getDeviceType().isIphone) {
downBtn.each(function (index) {
$(this).attr('href', $(this).attr('data-ios'));
});
}
if (getDeviceType().isAndroid) {
downBtn.each(function (index) {
$(this).attr('href', $(this).attr('data-android'));
});
}
}
// back to top
$('.come-back').bind('tapone',function () {
$('body').animate({scrollTop: 0});
});
};
/*
* @description: 获取设备类型
* @param: none
* @return: JSON
*/
function getDeviceType () {
var sUserAgent = navigator.userAgent.toLowerCase(),
bIsIphoneOs = sUserAgent.match(/iphone os/i) == "iphone os",
bIsAndroid = sUserAgent.match(/android/i) == "android",
bIsWeixin = sUserAgent.match(/MicroMessenger/i) == 'micromessenger';
return {
isIphone: bIsIphoneOs,
isAndroid: bIsAndroid,
isWeixin: bIsWeixin
}
}
exports.getDeviceType = getDeviceType;