hot-rank.page.js
3.81 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
let $ = require('yoho-jquery'),
Swiper = require('yoho-swiper'),
lazyLoad = require('yoho-jquery-lazyload'),
loading = require('plugin/loading'),
qs = require('yoho-qs');
let page = 1,
winH,
listTop,
notab = 0,
sort = '',
id = '',
hotrankNav,
noResult = '<p class="no-result">未找到相关搜索结果</p>';
require('common/suspend-cart');
require('common');
let share = require('common/share');
share({
title: '有货【会员日】开启啦!9月28日潮集狂欢趴等你来HI!限时6大福利,快参与起来喽~',
link: location.href,
desc: 'YOHO!BUY',
imgUrl: 'http://static.yohobuy.com/m/v1/img/touch/apple-touch-icon-144x144-precomposed-new.png'
});
function hotrank(pageIndex, sortIndex, tabId, noTab) {
loading.showLoadingMask();
$.ajax({
type: 'GET',
url: '/product/newsale/selectHotrank?' + sortIndex,
dataType: 'html',
data: {
page: pageIndex,
tab_id: tabId,
notab: noTab,
gender: qs.gender
},
success: function(data) {
if (data === ' ') {
if ($('.rank-main').length < 1 && $('.goods-nav').length < 1) {
$('#hotRank').html(noResult);
} else {
if (pageIndex === 1) {
hotrankNav = $('.goods-nav').prop('outerHTML');
$('#hotRank').html(hotrankNav + noResult);
}
}
} else {
$('.no-result').remove();
if (pageIndex === 1) {
$('.rank-main').remove();
}
$('#hotRank').append(data);
}
lazyLoad($('img.lazy'));
$('.rank-main ul li:gt(9)').find('.item-content i').removeClass('top');
winH = $(window).height();
if ($('.rank-main').length !== 0) {
$('#yoho-footer').css('position', 'static');
listTop = $('.rank-main').find('ul').offset().top;
} else {
$('#yoho-footer').css({
position: 'fixed',
width: '100%'
});
}
new Swiper('.s-goods-nav', {
grabCursor: true,
slidesPerView: 'auto',
slideElement: 'li'
});
loading.hideLoadingMask();
window.rePosFooter && window.rePosFooter();
}
});
}
function scrollHandler() {
if (page === 2) {
return;
}
if ($(window).scrollTop() + winH < listTop + $('#hotRank').height() - 100) {
return;
}
page = 2;
notab = 1;
hotrank(page, sort, id, notab);
}
$(window).scroll(function() {
window.requestAnimationFrame(scrollHandler);
});
hotrank(page, sort, id, notab);
$('#hotRank').on('touchend touchcancel', function() {
let ev = window.event;
let target = ev.target || ev.srcElement;
if (target.nodeName.toLowerCase() === 'span') {
$('.s-goods-nav .nav-item').removeClass('active');
target.parentNode.className = 'active ' + target.parentNode.className;
id = target.getAttribute('data-id') ? target.getAttribute('data-id') : '';
sort = target.getAttribute('data-sort') ? target.getAttribute('data-sort') : '';
page = 1;
notab = 1;
hotrank(page, sort, id, notab);
}
});
$('#hotRank').bind('contextmenu', function() {
return false;
});
$('#hotRank').on('touchstart', function() {
let ev = window.event;
let target = ev.target || ev.srcElement;
if (target.nodeName.toLowerCase() === 'span') {
target.parentNode.className = 'bg-active ' + target.parentNode.className;
}
}).on('touchend touchcancel', function() {
$('.s-goods-nav .nav-item').removeClass('bg-active');
});