Authored by 梁志锋

modify

... ... @@ -9,94 +9,139 @@ new Swiper('.swiper-container', {
autoplay: 3000
});
//img-lazyload
function lazyLoad(imgs) {
var $imgs;
if (typeof imgs === 'undefined') {
$imgs = $('img.lazy');
} else {
$imgs = imgs;
/**
* 初始化页面功能
*/
exports.init = function (url) {
//img-lazyload
function lazyLoad(imgs) {
var $imgs;
if (typeof imgs === 'undefined') {
$imgs = $('img.lazy');
} else {
$imgs = imgs;
}
$imgs.lazyload({
effect: 'fadeIn',
effect_speed: 10,
placeholder: 'data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw=='
});
}
$imgs.lazyload({
effect: 'fadeIn',
effect_speed: 10,
placeholder: 'data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw=='
});
}
lazyLoad();
var $newArrival = $('.new-arrival:last');
// 无最新单品推荐模块时直接返回
if ($newArrival.length === 0) {
return;
}
var isLogin = $('#is-login').val();
isLogin = isLogin ? isLogin : 'N';
//登录提示变量
var $loginTip = $('#login-tip');
lazyLoad();
var winH = $(window).height(),
loading = false,
end = false,
page = 1,
tpl;
var $goodList = $newArrival.children('.goods-list'),
mblTop = $newArrival.offset().top; //页面内容固定,可以预先求出高度
var $newArrival = $('.new-arrival:last');
//read good-info template
$.get('/common/goodinfo', function (data) {
tpl = '{{# goods}}' + data + '{{/ goods}}';
Mustache.parse(tpl);
});
//srcoll to load more
$(window).scroll(function () {
var num;
if (end || loading) {
// 无最新单品推荐模块时直接返回
if ($newArrival.length === 0) {
return;
}
if ($(window).scrollTop() + winH < mblTop + $newArrival.height()) {
return;
}
var isLogin = $('#is-login').val();
isLogin = isLogin ? isLogin : 'N';
//登录提示变量
var $loginTip = $('#login-tip');
var winH = $(window).height(),
loading = false,
end = false,
page = 1,
tpl;
var $father = $('.new-arrival-content');
//var $goodList = $newArrival.children('.goods-list'),
var mblTop = $newArrival.offset().top; //页面内容固定,可以预先求出高度
tpl = ["<div class=\"good-info\" data-id=\"{{id}}\">",
" <div class=\"tag-container clearfix\">",
" {{# tags}}",
" {{# isNew}}",
" <p class=\"good-tag new-tag\">NEW</p>",
" {{/ isNew}}",
" {{# isReNew}}",
" <p class=\"good-tag renew-tag\">再到着</p>",
" {{/ isReNew}}",
" {{# isSale}}",
" <p class=\"good-tag sale-tag\">SALE</p>",
" {{/ isSale}}",
" {{# isYohood}}",
" <div class=\"good-tag yohood-tag\"></div>",
" {{/ isYohood}}",
" {{# isLimit}}",
" <p class=\"good-tag limit-tag\">限量商品</p>",
" {{/ isLimit}}",
" {{/ tags}}",
" </div>",
" <div class=\"good-detail-img\">",
" <a class=\"good-islike {{# isLike}}good-like{{/ isLike}} iconfont\" href=\"{{likeUrl}}\">&#xe605;</a>",
" <a class=\"good-thumb\" href=\"{{url}}\">",
" <img class=\"lazy\" data-original=\"{{src}}\">",
" </a>",
" {{# isFew}}",
" <p class=\"few-tag\">即将售罄</p>",
" {{/ isFew}}",
" </div>",
" <div class=\"good-detail-text\">",
" <div class=\"name\">",
" <a href=\"{{url}}\">{{name}}</a>",
" </div>",
" <div class=\"price\">",
" <span class=\"sale-price {{^price}}no-price{{/price}}\">¥{{salePrice}}</span>",
" {{#price}}",
" <span class=\"market-price\">¥{{.}}</span>",
" {{/price}}",
" </div>",
" </div>",
"</div>"].join("");
tpl = '{{# goods}}' + tpl + '{{/ goods}}';
//read good-info template
/*$.get('/common/goodinfo', function (data) {
tpl = '{{# goods}}' + data + '{{/ goods}}';
Mustache.parse(tpl);
});*/
Mustache.parse(tpl);
loading = true;
num = $goodList.children('.good-info').length;
$.ajax({
type: 'GET',
url: '/goods/more',
data: {
//gender: 0, //性别
page: page + 1
//srcoll to load more
$(window).scroll(function () {
var num;
if (end || loading) {
return;
}
}).then(function (data) {
var res,
i;
if (data.code === 200) {
res = data.data;
if (res.end) {
end = res.end;
}
$goodList.append(Mustache.render(tpl, {
goods: res.goods
}));
//lazyLoad
lazyLoad($goodList.children('.good-info:gt(' + (num - 1) + ')').find('img.lazy'));
loading = false;
page++;
if ($(window).scrollTop() + winH < mblTop + $newArrival.height()) {
return;
}
});
});
loading = true;
num = $father.children('.good-info').length;
$.ajax({
type: 'GET',
url: url,
data: {
//gender: 0, //性别
page: page + 1
}
}).then(function (data) {
var res,
i;
if (data.code === 200) {
res = data.data;
if (res.end) {
end = res.end;
}
console.log("aaa");
$father.append(Mustache.render(tpl, {
goods: res.goods
}));
//lazyLoad
lazyLoad($father.children('.good-info:gt(' + (num - 1) + ')').find('img.lazy'));
loading = false;
page++;
}
});
});
};
... ...
<script src="http://localhost:8000/public/js/new-festival.js"></script>
<script type="text/javascript">
seajs.use('public/js/new-festival');
seajs.use('public/js/new-festival',function(newfestival){
newfestival.init('url');
});
</script>
\ No newline at end of file
... ...