|
@@ -11,8 +11,7 @@ var $ = require('jquery'), |
|
@@ -11,8 +11,7 @@ var $ = require('jquery'), |
11
|
|
11
|
|
12
|
var $authorIntro = $('.author .intro');
|
12
|
var $authorIntro = $('.author .intro');
|
13
|
|
13
|
|
14
|
-var isEzinPage = false,
|
|
|
15
|
- isIphone = navigator.userAgent.indexOf('iPhone') > 0 ? true : false;
|
14
|
+var pageInIscroll = false;
|
16
|
|
15
|
|
17
|
var hasCollocationBlock = $('.collocation-block').length > 0 ? true : false;
|
16
|
var hasCollocationBlock = $('.collocation-block').length > 0 ? true : false;
|
18
|
|
17
|
|
|
@@ -42,7 +41,7 @@ function posCollocationArrow($curCo) { |
|
@@ -42,7 +41,7 @@ function posCollocationArrow($curCo) { |
42
|
backgroundPosition: bgPos + ' bottom'
|
41
|
backgroundPosition: bgPos + ' bottom'
|
43
|
});
|
42
|
});
|
44
|
|
43
|
|
45
|
- if (isIphone && !isEzinPage) {
|
44
|
+ if (pageInIscroll) {
|
46
|
$fixedThumbContainer.css({
|
45
|
$fixedThumbContainer.css({
|
47
|
backgroundPosition: bgPos + ' bottom'
|
46
|
backgroundPosition: bgPos + ' bottom'
|
48
|
});
|
47
|
});
|
|
@@ -62,7 +61,7 @@ function thumbTouchEvt(e) { |
|
@@ -62,7 +61,7 @@ function thumbTouchEvt(e) { |
62
|
|
61
|
|
63
|
$thumbs.filter('.focus').removeClass('focus');
|
62
|
$thumbs.filter('.focus').removeClass('focus');
|
64
|
|
63
|
|
65
|
- if (isIphone && !isEzinPage) {
|
64
|
+ if (pageInIscroll) {
|
66
|
if ($curCo.closest('.fixed-thumb-container').length > 0) {
|
65
|
if ($curCo.closest('.fixed-thumb-container').length > 0) {
|
67
|
$brother = $thumbContainer;
|
66
|
$brother = $thumbContainer;
|
68
|
} else {
|
67
|
} else {
|
|
@@ -86,7 +85,7 @@ function thumbTouchEvt(e) { |
|
@@ -86,7 +85,7 @@ function thumbTouchEvt(e) { |
86
|
//
|
85
|
//
|
87
|
lazyLoad($curProds.find('.lazy'));
|
86
|
lazyLoad($curProds.find('.lazy'));
|
88
|
|
87
|
|
89
|
- if (isIphone && !isEzinPage) {
|
88
|
+ if (pageInIscroll) {
|
90
|
if (myScroll) {
|
89
|
if (myScroll) {
|
91
|
myScroll.scrollToElement(scrollToEl, 400);
|
90
|
myScroll.scrollToElement(scrollToEl, 400);
|
92
|
}
|
91
|
}
|
|
@@ -99,76 +98,17 @@ function thumbTouchEvt(e) { |
|
@@ -99,76 +98,17 @@ function thumbTouchEvt(e) { |
99
|
myScroll && myScroll.refresh();
|
98
|
myScroll && myScroll.refresh();
|
100
|
}
|
99
|
}
|
101
|
|
100
|
|
102
|
-if (isIphone && !isEzinPage) {
|
|
|
103
|
- if ($('.yoho-header').length > 0) {
|
|
|
104
|
- $('#wrapper').addClass('ios has-head');
|
|
|
105
|
- } else {
|
|
|
106
|
- $('#wrapper').addClass('ios');
|
|
|
107
|
- }
|
|
|
108
|
-}
|
|
|
109
|
-
|
|
|
110
|
-ellipsis.init();
|
|
|
111
|
-
|
|
|
112
|
-lazyLoad($('.lazy'));
|
|
|
113
|
-
|
|
|
114
|
-//title mlellipsis
|
|
|
115
|
-$('.info-list .title, .one-good .reco-name').each(function() {
|
|
|
116
|
- this.mlellipsis(2);
|
|
|
117
|
-});
|
|
|
118
|
-
|
|
|
119
|
-//offset.left约等于marginLeft的值则表示介绍被换行,则清除intro的paddingTop让其更靠近头像和作者名
|
|
|
120
|
-if ($authorIntro.offset() && (parseInt($authorIntro.offset().left, 10) ===
|
|
|
121
|
- parseInt($authorIntro.css('margin-left'), 10))) {
|
|
|
122
|
- $authorIntro.css('padding-top', 0);
|
|
|
123
|
-}
|
|
|
124
|
-
|
|
|
125
|
-//有搭配模块,iphone使用iscroll初始化滚动并有固定的搭配栏,其他的没有
|
|
|
126
|
-if (hasCollocationBlock) {
|
|
|
127
|
- $coBlock = $('.collocation-block');
|
|
|
128
|
- $thumbContainer = $coBlock.children('.thumb-container');
|
|
|
129
|
- $thumbs = $thumbContainer.find('li');
|
|
|
130
|
- $prods = $coBlock.find('.prod');
|
|
|
131
|
-
|
|
|
132
|
- thumbWidth = $thumbs.width();
|
|
|
133
|
-
|
|
|
134
|
- if (isIphone) {
|
|
|
135
|
- $fixedThumbContainer = $('#wrapper')
|
|
|
136
|
- .after($thumbContainer.clone().addClass('fixed-thumb-container fixed-bottom'))
|
|
|
137
|
- .next('.thumb-container');
|
|
|
138
|
-
|
|
|
139
|
- //load img of fixed thumb container
|
|
|
140
|
- lazyLoad($fixedThumbContainer.find('.lazy'), {
|
|
|
141
|
- event: 'sporty'
|
|
|
142
|
- });
|
|
|
143
|
- }
|
|
|
144
|
-
|
|
|
145
|
- //Init Arrow Position
|
|
|
146
|
- posCollocationArrow($thumbs.filter('.focus'));
|
|
|
147
|
-
|
|
|
148
|
- $thumbContainer.delegate('.thumb', 'touchend', thumbTouchEvt);
|
|
|
149
|
-
|
|
|
150
|
- if (isIphone && !isEzinPage) {
|
|
|
151
|
- $fixedThumbContainer.delegate('.thumb', 'touchend', thumbTouchEvt);
|
|
|
152
|
- }
|
|
|
153
|
-}
|
|
|
154
|
-
|
|
|
155
|
-/**
|
|
|
156
|
- * 初始化页面参数
|
|
|
157
|
- */
|
|
|
158
|
-exports.init = function(flag) {
|
|
|
159
|
- if (flag === true) {
|
|
|
160
|
- isEzinPage = true;
|
|
|
161
|
- }
|
|
|
162
|
-};
|
|
|
163
|
-
|
|
|
164
|
// 初始化iscroll
|
101
|
// 初始化iscroll
|
165
|
-window.onload = function() {
|
|
|
166
|
- var $scroller = $('#scroller');
|
102
|
+function initIscroll() {
|
|
|
103
|
+ var $scroller = $('#scroller'),
|
|
|
104
|
+ $yohoHeader = $('.yoho-header');
|
167
|
|
105
|
|
168
|
- var winH, tcH, cbH, cbTop, fixedThumbDom;
|
106
|
+ var hH = 0,
|
|
|
107
|
+ winH, tcH, cbH, cbTop, fixedThumbDom;
|
169
|
|
108
|
|
170
|
- if (!isIphone || isEzinPage) {
|
|
|
171
|
- return;
|
109
|
+ //考虑通用头部的影响:对offset().top以及winH做对应偏移
|
|
|
110
|
+ if ($yohoHeader.length > 0) {
|
|
|
111
|
+ hH = $yohoHeader.outerHeight();
|
172
|
}
|
112
|
}
|
173
|
|
113
|
|
174
|
myScroll = new IScroll('#wrapper', {
|
114
|
myScroll = new IScroll('#wrapper', {
|
|
@@ -188,12 +128,12 @@ window.onload = function() { |
|
@@ -188,12 +128,12 @@ window.onload = function() { |
188
|
return;
|
128
|
return;
|
189
|
}
|
129
|
}
|
190
|
|
130
|
|
191
|
- winH = $(window).height();
|
131
|
+ winH = $(window).height() - hH;
|
192
|
fixedThumbDom = $fixedThumbContainer[0];
|
132
|
fixedThumbDom = $fixedThumbContainer[0];
|
193
|
|
133
|
|
194
|
- tcH = $thumbContainer.height();
|
|
|
195
|
- cbH = $coBlock.height();
|
|
|
196
|
- cbTop = $coBlock.offset().top;
|
134
|
+ tcH = $thumbContainer.outerHeight();
|
|
|
135
|
+ cbH = $coBlock.outerHeight();
|
|
|
136
|
+ cbTop = $coBlock.offset().top - hH;
|
197
|
|
137
|
|
198
|
myScroll.on('scroll', function() {
|
138
|
myScroll.on('scroll', function() {
|
199
|
var sTop = -this.y;
|
139
|
var sTop = -this.y;
|
|
@@ -224,7 +164,7 @@ window.onload = function() { |
|
@@ -224,7 +164,7 @@ window.onload = function() { |
224
|
.addClass('absolute')
|
164
|
.addClass('absolute')
|
225
|
.removeClass('fixed-top hide');
|
165
|
.removeClass('fixed-top hide');
|
226
|
}
|
166
|
}
|
227
|
- fixedThumbDom.style.top = cbTop + cbH - tcH - sTop + 'px';
|
167
|
+ fixedThumbDom.style.top = cbTop + hH + cbH - tcH - sTop + 'px';
|
228
|
} else if (sTop > cbTop + cbH) {
|
168
|
} else if (sTop > cbTop + cbH) {
|
229
|
if (classList.indexOf('hide') === -1) {
|
169
|
if (classList.indexOf('hide') === -1) {
|
230
|
$fixedThumbContainer
|
170
|
$fixedThumbContainer
|
|
@@ -234,4 +174,75 @@ window.onload = function() { |
|
@@ -234,4 +174,75 @@ window.onload = function() { |
234
|
}
|
174
|
}
|
235
|
$scroller.trigger('scroll');
|
175
|
$scroller.trigger('scroll');
|
236
|
});
|
176
|
});
|
|
|
177
|
+}
|
|
|
178
|
+
|
|
|
179
|
+//window onload 后重新refresh iscroll
|
|
|
180
|
+window.onload = function() {
|
|
|
181
|
+ myScroll && myScroll.refresh();
|
|
|
182
|
+};
|
|
|
183
|
+
|
|
|
184
|
+//初始化页面,包括是否使用iscorll初始化页面
|
|
|
185
|
+//接口暴露在HTML中,使用压缩名
|
|
|
186
|
+exports.i = function(useIscroll) {
|
|
|
187
|
+ var isIphone = navigator.userAgent.indexOf('iPhone') > 0 ? true : false;
|
|
|
188
|
+
|
|
|
189
|
+ pageInIscroll = isIphone && useIscroll;
|
|
|
190
|
+
|
|
|
191
|
+ ellipsis.init();
|
|
|
192
|
+
|
|
|
193
|
+ lazyLoad($('.lazy'));
|
|
|
194
|
+
|
|
|
195
|
+ //title mlellipsis
|
|
|
196
|
+ $('.info-list .title, .one-good .reco-name').each(function() {
|
|
|
197
|
+ this.mlellipsis(2);
|
|
|
198
|
+ });
|
|
|
199
|
+
|
|
|
200
|
+ //offset.left约等于marginLeft的值则表示介绍被换行,则清除intro的paddingTop让其更靠近头像和作者名
|
|
|
201
|
+ if ($authorIntro.offset() && (parseInt($authorIntro.offset().left, 10) ===
|
|
|
202
|
+ parseInt($authorIntro.css('margin-left'), 10))) {
|
|
|
203
|
+ $authorIntro.css('padding-top', 0);
|
|
|
204
|
+ }
|
|
|
205
|
+
|
|
|
206
|
+ if (pageInIscroll) {
|
|
|
207
|
+ if ($('.yoho-header').length > 0) {
|
|
|
208
|
+ $('#wrapper').addClass('ios has-head');
|
|
|
209
|
+ } else {
|
|
|
210
|
+ $('#wrapper').addClass('ios');
|
|
|
211
|
+ }
|
|
|
212
|
+ }
|
|
|
213
|
+
|
|
|
214
|
+ //有搭配模块,iphone使用iscroll初始化滚动并有固定的搭配栏,其他的没有
|
|
|
215
|
+ if (hasCollocationBlock) {
|
|
|
216
|
+ $coBlock = $('.collocation-block');
|
|
|
217
|
+ $thumbContainer = $coBlock.children('.thumb-container');
|
|
|
218
|
+ $thumbs = $thumbContainer.find('li');
|
|
|
219
|
+ $prods = $coBlock.find('.prod');
|
|
|
220
|
+
|
|
|
221
|
+ thumbWidth = $thumbs.width();
|
|
|
222
|
+
|
|
|
223
|
+ if (pageInIscroll) {
|
|
|
224
|
+ $fixedThumbContainer = $('#wrapper')
|
|
|
225
|
+ .after($thumbContainer.clone().addClass('fixed-thumb-container fixed-bottom'))
|
|
|
226
|
+ .next('.thumb-container');
|
|
|
227
|
+
|
|
|
228
|
+ //load img of fixed thumb container
|
|
|
229
|
+ lazyLoad($fixedThumbContainer.find('.lazy'), {
|
|
|
230
|
+ event: 'sporty'
|
|
|
231
|
+ });
|
|
|
232
|
+ }
|
|
|
233
|
+
|
|
|
234
|
+ //Init Arrow Position
|
|
|
235
|
+ posCollocationArrow($thumbs.filter('.focus'));
|
|
|
236
|
+
|
|
|
237
|
+ $thumbContainer.delegate('.thumb', 'touchend', thumbTouchEvt);
|
|
|
238
|
+
|
|
|
239
|
+ if (pageInIscroll) {
|
|
|
240
|
+ $fixedThumbContainer.delegate('.thumb', 'touchend', thumbTouchEvt);
|
|
|
241
|
+
|
|
|
242
|
+ }
|
|
|
243
|
+ }
|
|
|
244
|
+
|
|
|
245
|
+ if (pageInIscroll) {
|
|
|
246
|
+ initIscroll();
|
|
|
247
|
+ }
|
237
|
}; |
248
|
}; |