best-for-you.js
689 Bytes
var $ = require('yoho.jquery');
(function() {
var $bestForYou = $('#best-for-you');
var $box, boxInfo;
if (!$bestForYou.length) {
return;
}
$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;
});
}
})();