home.js
7.24 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/**
* 文件功能描述 :首页JS
* 使用方法 :直接use
* author :wei.wang@yoho.cn
* date :2015-4-23
*/
var $ = require("jquery"),
mlellipsis = require("mlellipsis");
require("lazyload");
var Swiper = require("yoho-idangerous.swiper"),
tips = require("yoho-tips"),
box = require("yoho-box");
var isFixed = false,
pop = null,
popTop = null,
popLeft = null,
limitTop = null,
stopTop = null,
stopLeft = null;
var clientWidth = $(window).width();
//住显示区域行数计算
var totalLineNum = 7,
maxTitleStrNum = 45,
maxDetailStrNum = 22,
citems = $(".item-text-area"),
titleLineNum = 0;
subTitleLineNum = 0;
detailLineNum = 0;
detailStr = "";
self = null;
mlellipsis.init();
//pop=============================================================================================
if ($(".pop-container")[0] != null) {
popTop = $(".pop-container").offset().top;
popLeft = $(".content").offset().left + $(".content").width() - $(".pop-container").width();
limitTop = $(".pager-content-default").offset().top + $(".pager-content-default").height() + 2 - $(".pop-container").height();
stopTop = $(".pager-content-default").offset().top - $(".pop-container").height();
stopLeft = $(".bottom-item-container").offset().left + $(".bottom-item-container").width() - $(".pop-container").width();
pop = new Swiper('.swiper-container3', {
loop: true,
autoplay: 5000,
autoStopPlay: false,
paginationClickable: true,
onSlideChangeEnd: function() {
pop.startAutoplay();
$(".swiper-container3 .lazy").lazyload();
}
});
$('.prev-button').bind('click', function(e) {
e.preventDefault();
pop.swipePrev();
});
$('.next-button').bind('click', function(e) {
e.preventDefault();
pop.swipeNext();
});
if (limitTop - popTop > $(".pop-container").height()) {
$(window).bind("scroll", function() {
if ($(document).scrollTop() >= popTop &&
isFixed === false &&
$(document).scrollTop() < limitTop &&
clientWidth > 768) {
isFixed = true;
$(".pop-container-bottom").attr("class", "pop-container");
$(".pop-container").css({
position: "fixed",
top: 0,
left: popLeft
});
} else if ($(document).scrollTop() > limitTop && clientWidth > 768) {
$(".pop-container").removeAttr("style");
if ($(".swiper-container2")[0] != null) {
$(".pop-container").css({
"border-top": 0
});
}
$(".pop-container").attr("class", "pop-container-bottom");
isFixed = false;
} else if (isFixed === true && $(document).scrollTop() < popTop && clientWidth > 768) {
isFixed = false;
$(".pop-container").removeAttr("style");
if ($(".swiper-container2")[0] != null) {
$(".pop-container").css({
"border-top": 0
});
}
}
});
}
window.onresize = function() {
clientWidth = $(window).width();
popTop = $(".pop-container").offset().top;
popLeft = $(".content").offset().left + $(".content").width() - $(".pop-container").width();
limitTop = $(".pager-content-default").offset().top + $(".pager-content-default").height() + 2 - $(".pop-container").height();
stopTop = $(".pager-content-default").offset().top - $(".pop-container").height();
stopLeft = $(".bottom-item-container").offset().left + $(".bottom-item-container").width() - $(".pop-container").width();
if (isFixed === true) {
$(".pop-container").css({
"left": popLeft
});
}
};
var maxLineNum = 5;
$(".pop-link").find(".detail").mlellipsis(3, "pop-detail");
}
//================================================================================================
//首页碎片交互=================================================================================================
//mulLine.init();
function dealItems() {
if (!citems.length) {
return;
}
if (document.body.clientWidth < 1190 && document.body.clientWidth > 768) {
totalLineNum = 6;
// 6 行
maxTitleStrNum = 39;
// 13个字
maxDetailStrNum = 20;
// 18个字
} else if (document.body.clientWidth <= 768) {
totalLineNum = 5;
// 6 行
maxTitleStrNum = 12;
// 13个字
maxDetailStrNum = 15;
}
titleLineNum = 0;
subTitleLineNum = 0;
detailLineNum = 0;
detailStr = "";
self = null;
citems.each(function() {
self = $(this);
var itemTitleObj = self.find(".item-title:first"),
subTitle = itemTitleObj.next();
// 主标题行数
titleLineNum = 1;
if (maxTitleStrNum < itemTitleObj.attr("_title").length) {
titleLineNum = 2;
itemTitleObj.text(itemTitleObj.attr('_title').substring(0, (maxTitleStrNum - 1) * 2) + '...');
}
// 副标题行数
subTitleLineNum = 1;
if (maxTitleStrNum < itemTitleObj.next().attr("_title").length) {
subTitleLineNum = 2;
subTitle.text(subTitle.attr('_title').substring(0, (maxTitleStrNum - 1) * 2) + '...');
}
// 摘要内容行数
detailLineNum = totalLineNum - titleLineNum - subTitleLineNum;
if ((maxDetailStrNum * detailLineNum) < self.find(".item-detail").attr("_title").length) {
detailStr = self.find(".item-detail").attr("_title").substring(0, (maxDetailStrNum - 1) * (detailLineNum)) + " ...";
self.find(".item-detail").text(detailStr.replace(/[a-zA-Z]+?\s{1}\.\.\.\$/, " ..."));
} else {
self.find(".content-item-detail").text(self.find(".content-item-detail").attr("_title"));
}
});
citems = null;
}
dealItems();
//=============================================================
//邮件订阅=============================================================================================================
$(".followus-button").click(function() {
if ($(".follow-us-input-content input").val() == '') {
box.alert(tips.getTips("emailEmpty"));
return;
}
if (!tools.IYOHO_isEmail($(".follow-us-input-content input").val())) {
box.alert(tips.getTips("emailError"));
return;
}
$(".search-suggest").hide();
window.open('/passport/subscribe/index?email=' + $(".follow-us-input-content input").val());
});
$(".followus-input").keydown(function(event) {
if (event.keyCode == 13) {
$(".followus-button").trigger("click");
}
});
//===================================================================================================================