Authored by ccbikai

为您优选异步化

... ... @@ -5,14 +5,23 @@
*/
var Swiper = require('yoho.iswiper');
var Swiper = require('yoho.iswiper'),
$ = require('jquery');
var recommendSwiper;
var recommendSwiper,
$recommendForYou = $('.recommend-for-you');
recommendSwiper = new Swiper('#swiper-recommend', {
slidesPerView: 'auto',
grabCursor: true,
slideElement: 'li',
lazyLoading: true,
watchSlidesVisibility: true
$.get('/home/preference').then(function(html) {
$recommendForYou.html(html);
if ($('#swiper-recommend').length) {
recommendSwiper = new Swiper('#swiper-recommend', {
slidesPerView: 'auto',
grabCursor: true,
slideElement: 'li',
lazyLoading: true,
watchSlidesVisibility: true
});
}
}).fail(function() {
$recommendForYou.hide();
});
\ No newline at end of file
... ...
{{> product/recommend-content}}
\ No newline at end of file
... ...
<div class="title">为您优选新品</div>
<div id="swiper-recommend" class="swiper-container">
<ul class="swiper-wrapper swiper-wrapper-recommend">
{{#recommendList}}
<li class="swiper-slide">
<img class="swiper-lazy img-box" data-src="{{thumb}}">
<div class="price">
<span class="sale-price {{^price}}no-price{{/price}}">¥{{salePrice}}</span>
{{#price}}<span class="old-price">¥{{.}}</span>{{/price}}
</div>
<div class="swiper-lazy-preloader"></div>
</li>
{{/recommendList}}
</ul>
</div>
\ No newline at end of file
... ...
{{# recommendForYou}}
<div class="recommend-for-you">
<div class="title">为您优选新品</div>
<div id="swiper-recommend" class="swiper-container">
<ul class="swiper-wrapper swiper-wrapper-recommend">
{{#recommendList}}
<li class="swiper-slide">
<img class="swiper-lazy img-box" data-src="{{thumb}}">
<div class="price">
<span class="sale-price {{^price}}no-price{{/price}}"{{salePrice}}</span>
{{#price}}<span class="old-price"{{.}}</span>{{/price}}
</div>
<div class="swiper-lazy-preloader"></div>
</li>
{{/recommendList}}
</ul>
</div>
</div>
{{/ recommendForYou}}
\ No newline at end of file
<div class="recommend-for-you">
</div>
\ No newline at end of file
... ...