best-for-you.js
1.42 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
var $ = require('yoho-jquery');
var bestForYouPage = {},
$bestForYou = $('.best-for-you');
var bestForYouHbs = require('hbs/common/best-for-you.hbs');
bestForYouPage = {
init: function() {
if (!$bestForYou.length) {
return;
}
this.getRecommend();
},
getRecommend: function() {
var _this = this;
$.ajax({
url: '/common/getRecommend',
type: 'POST',
dataType: 'json',
data: {
recPos: 100004,
limit: 15
},
success: function(d) {
$bestForYou.html(bestForYouHbs({bestForYou: d}));
_this.changeNext();
}
});
},
// 换一批按钮
changeNext: function() {
var $box, boxInfo;
$box = $bestForYou.children('.product-wrap');
boxInfo = {
index: 0,
width: $box.find('li').width() + 10,
totalPage: Math.ceil(($box.find('li').length + 1) / 5)
};
if (boxInfo.totalPage > 1) {
boxInfo.totalPage = boxInfo.totalPage > 3 ? 3 : boxInfo.totalPage;
$bestForYou.find('.change-btn').show().click(function() {
boxInfo.index++;
$box.get(0).scrollLeft = (boxInfo.index % boxInfo.totalPage) * boxInfo.width * 5;
});
}
}
};
$(document).ready(function() {
bestForYouPage.init();
});