-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
110 lines (99 loc) · 3.04 KB
/
main.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
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
require([], function (){
var isMobileInit = false;
var loadMobile = function(){
require(['/js/mobile.js'], function(mobile){
mobile.init();
isMobileInit = true;
});
}
var isPCInit = false;
var loadPC = function(){
require(['/js/pc.js'], function(pc){
pc.init();
isPCInit = true;
});
}
var browser={
versions:function(){
var u = window.navigator.userAgent;
return {
trident: u.indexOf('Trident') > -1, //IE内核
presto: u.indexOf('Presto') > -1, //opera内核
webKit: u.indexOf('AppleWebKit') > -1, //苹果、谷歌内核
gecko: u.indexOf('Gecko') > -1 && u.indexOf('KHTML') == -1, //火狐内核
mobile: !!u.match(/AppleWebKit.*Mobile.*/), //是否为移动终端
ios: !!u.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/), //ios终端
android: u.indexOf('Android') > -1 || u.indexOf('Linux') > -1, //android终端或者uc浏览器
iPhone: u.indexOf('iPhone') > -1 || u.indexOf('Mac') > -1, //是否为iPhone或者安卓QQ浏览器
iPad: u.indexOf('iPad') > -1, //是否为iPad
webApp: u.indexOf('Safari') == -1 ,//是否为web应用程序,没有头部与底部
weixin: u.indexOf('MicroMessenger') == -1 //是否为微信浏览器
};
}()
}
$(window).bind("resize", function(){
if(isMobileInit && isPCInit){
$(window).unbind("resize");
return;
}
var w = $(window).width();
if(w >= 700){
loadPC();
}else{
loadMobile();
}
});
if(browser.versions.mobile === true || $(window).width() < 700){
loadMobile();
}else{
loadPC();
}
//是否使用fancybox
if(yiliaConfig.fancybox === true){
require(['/fancybox/jquery.fancybox.js'], function(pc){
var isFancy = $(".isFancy");
if(isFancy.length != 0){
var imgArr = $(".article-inner img");
for(var i=0,len=imgArr.length;i<len;i++){
var src = imgArr.eq(i).attr("src");
var title = imgArr.eq(i).attr("alt");
imgArr.eq(i).replaceWith("<a href='"+src+"' title='"+title+"' rel='fancy-group' class='fancy-ctn fancybox'><img src='"+src+"' title='"+title+"'></a>");
}
$(".article-inner .fancy-ctn").fancybox();
}
});
}
//是否开启动画
if(yiliaConfig.animate === true){
require(['/js/jquery.lazyload.js'], function(){
//avatar
$(".js-avatar").attr("src", $(".js-avatar").attr("lazy-src"));
$(".js-avatar")[0].onload = function(){
$(".js-avatar").addClass("show");
}
});
if(yiliaConfig.isHome === true){
//content
function showArticle(){
$(".article").each(function(){
if( $(this).offset().top <= $(window).scrollTop()+$(window).height() && !($(this).hasClass('show')) ) {
$(this).removeClass("hidden").addClass("show");
$(this).addClass("is-hiddened");
}else{
if(!$(this).hasClass("is-hiddened")){
$(this).addClass("hidden");
}
}
});
}
$(window).on('scroll', function(){
showArticle();
});
showArticle();
}
}
//是否新窗口打开链接
if(yiliaConfig.open_in_new == true){
$(".article a[href]").attr("target", "_blank")
}
});