Authored by 郭成尧

lazyload

... ... @@ -2,10 +2,18 @@
<a {{#if link}}href="{{link}}"{{/if}}>
{{#if isGood}}
{{#ifor triple double}}
<img class="item-pic" src="{{image2 src w=235 h=314}}" alt="">
{{#within index 3}}
<img class="item-pic" src="{{image2 src w=235 h=314}}">
{{^}}
<img class="item-pic lazy" data-original="{{image2 src w=235 h=314}}">
{{/within}}
{{/ifor}}
{{^}}
<img class="item-pic" src="{{image2 src}}" alt="">
{{#within index 3}}
<img class="item-pic" src="{{image2 src}}" alt="">
{{^}}
<img class="item-pic lazy" data-original="{{image2 src}}">
{{/within}}
{{/if}}
</a>
... ...
... ... @@ -15,13 +15,13 @@
<ul class="swiper-wrapper">
{{#each ../pics}}
<li class="swiper-slide">
{{#if link}}
<a href="{{link}}">
<a{{#if link}} href="{{link}}"{{/if}}>
{{#within @../index 3}}
<img src="{{image2 src}}" alt="">
</a>
{{^}}
<img src="{{image2 src}}" alt="">
{{/if}}
{{^}}
<img class="lazy" data-original="{{image2 src}}" alt="">
{{/within}}
</a>
</li>
{{/each}}
</ul>
... ... @@ -51,7 +51,7 @@
{{#isEqual module_type 'SingleImage'}}
<div class="items-s1 clearfix">
{{#each ../pics}}
{{> reds-shop/item}}
{{> reds-shop/item index=@../index}}
{{/each}}
</div>
{{#if ../isModuleMargin}}
... ... @@ -61,7 +61,7 @@
{{#isEqual module_type 'DoubleImage'}}
<div class="items-s2 clearfix">
{{#each ../pics}}
{{> reds-shop/item double=true}}
{{> reds-shop/item index=@../index double=true}}
{{/each}}
</div>
{{#if ../isModuleMargin}}
... ... @@ -71,7 +71,7 @@
{{#isEqual module_type 'TripleImage'}}
<div class="{{#isEqual ../displayType 1}}items-3-3{{/isEqual}}{{#isEqual ../displayType 2}}items-3-3 items-small{{/isEqual}}{{#isEqual ../displayType 3}}items-3-2 items-3-2-right{{/isEqual}}{{#isEqual ../displayType 4}}items-3-2 items-3-2-left{{/isEqual}} clearfix">
{{#each ../pics}}
{{> reds-shop/item triple=true}}
{{> reds-shop/item index=@../index triple=true}}
{{/each}}
</div>
{{#if ../isModuleMargin}}
... ... @@ -81,7 +81,7 @@
{{#isEqual module_type 'FourImage'}}
<div class="items-s4 clearfix">
{{#each ../pics}}
{{> reds-shop/item four=true}}
{{> reds-shop/item index=@../index four=true}}
{{/each}}
</div>
{{#if ../isModuleMargin}}
... ...
... ... @@ -2,7 +2,7 @@
* @Author: Targaryen
* @Date: 2017-03-23 11:31:51
* @Last Modified by: Targaryen
* @Last Modified time: 2017-04-25 10:56:07
* @Last Modified time: 2017-04-25 11:45:13
*/
/** *****************
... ... @@ -17,6 +17,49 @@ let $collect = $('#collect');
const shopId = $('#shopId').val();
lazyLoad($('.lazy'));
/**
* 异步检测是否已经收藏
*/
$.ajax({
type: 'GET',
url: location.protocol + '//m.yohobuy.com/product/index/shopFav',
xhrFields: {
withCredentials: true
},
data: {
shopId: shopId
},
success: function(data) {
if (data.collect) {
$collect.attr('class', 'already-collect pull-left');
}
},
error: function() {
tip.show('网络断开连接了~');
}
});
/**
* 店铺轮播图
*/
if ($('.shop-swiper')) {
let num = $('.shop-swiper').length;
for (let i = 1; i <= num; i++) {
new Swiper2('.shop-swiper-' + i, {
lazyLoading: true,
lazyLoadingInPrevNext: true,
loop: true,
autoplay: 3000,
slideElement: 'li',
paginationClickable: true,
pagination: $(this).closest('.shop-swiper-' + i).find('.pagination-inner').get(0)
});
}
}
/**
* 异步加载推荐商品
*/
... ... @@ -49,51 +92,33 @@ $.each($goodsContainer, function(index, elem) {
},
data: data,
success: function(result) {
let $result = $(result);
lazyLoad($result.find('img[class=lazy]'));
$(elem).html(result);
}
});
});
/**
* 异步检测是否已经收藏
* 异步加载首页全部商品
*/
$.ajax({
type: 'GET',
url: location.protocol + '//m.yohobuy.com/product/index/shopFav',
url: '/product/search/search',
xhrFields: {
withCredentials: true
},
data: {
shopId: shopId
},
success: function(data) {
if (data.collect) {
$collect.attr('class', 'already-collect pull-left');
}
shop_id: shopId
},
error: function() {
tip.show('网络断开连接了~');
}
});
/**
* 店铺轮播图
*/
if ($('.shop-swiper')) {
let num = $('.shop-swiper').length;
success: function(result) {
let $result = $(result);
for (let i = 1; i <= num; i++) {
new Swiper2('.shop-swiper-' + i, {
lazyLoading: true,
lazyLoadingInPrevNext: true,
loop: true,
autoplay: 3000,
slideElement: 'li',
paginationClickable: true,
pagination: $(this).closest('.shop-swiper-' + i).find('.pagination-inner').get(0)
});
lazyLoad($result.find('img[class=lazy]'));
$indexGoodsContaniner.find('.container').html($result);
}
}
});
/**
* 店铺收藏取消收藏操作
... ... @@ -136,23 +161,3 @@ $collect.on('click', function() {
}
});
});
/**
* 异步加载首页全部商品
*/
$.ajax({
type: 'GET',
url: '/product/search/search',
xhrFields: {
withCredentials: true
},
data: {
shop_id: shopId
},
success: function(result) {
let $result = $(result);
lazyLoad($result.find('img[class=lazy]'));
$indexGoodsContaniner.find('.container').html($result);
}
});
... ...