home.js
2.12 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
/**
* 逛首页
* @author: xuqi<qi.xu@yoho.cn>
* @date: 2015/10/10
*/
var $ = require('yoho.zepto'),
Swiper = require('yoho.iswiper');
var info = require('./info'),
setLazyLoadAndMellipsis = info.setLazyLoadAndMellipsis,
loadMore = info.loadMore;
var $loadMoreInfo = $('#load-more-info');
var $loading = $(''),
$noMore = $('');
var winH = $(window).height(),
loadMoreH = $loadMoreInfo.height();
var $infoList = $('#info-list'),
$infos = $infoList.children('.info-list'),
$nav = $('#guang-nav'),
$curNav = $nav.children('.focus'),
curType = $curNav.data('type');
var state = {};
var mySwiper;
if ($loadMoreInfo.length > 0) {
$loading = $loadMoreInfo.children('.loading');
$noMore = $loadMoreInfo.children('.no-more');
}
mySwiper = new Swiper('.swiper-container', {
lazyLoading: true,
pagination: '.swiper-pagination'
});
info.initInfosEvt($infoList);
//初始化各Nav下资讯加载的状态
(function() {
var gender = $('#gender').val();
$nav.children('.guang-nav-item').each(function() {
var type = $(this).data('type');
state[type] = {
page: 1,
gender: gender,
type: type,
end: false
};
});
}());
$nav.delegate('.guang-nav-item', 'touchstart', function() {
var $this = $(this),
$content,
index;
if ($this.hasClass('focus')) {
return;
}
index = $this.index();
$this.addClass('focus');
$curNav.removeClass('focus');
$infos.not('.hide').addClass('hide');
$content = $infos.eq(index);
$content.removeClass('hide');
//lazyload & mellipsis
setLazyLoadAndMellipsis($content.children('.guang-info'));
$curNav = $this;
curType = $this.data('type');
//重置当前Tab的load-more
if (state[curType].end) {
$loading.addClass('hide');
$noMore.removeClass('hide');
} else {
$loading.removeClass('hide');
$noMore.addClass('hide');
}
});
$(document).scroll(function() {
if ($(window).scrollTop() + winH >= $(document).height() - loadMoreH) {
loadMore($infos, state[curType]);
}
});