Authored by 沈志敏

采用懒加载

... ... @@ -15,7 +15,11 @@
<div {{#if param.anchorname}}id="{{param.anchorname}}"{{/if}} {{#if param.tabname}}tabname="{{param.tabname}}"{{/if}} {{#if id}}data-id="{{id}}"{{/if}} class="floor {{type}}"
style="{{#if param.bgcolor}}background-color:{{param.bgcolor}}{{/if}}">
{{#if param.bgimg}}
<img src="{{image2 param.bgimg q=60}}">
{{#isLazyLoad type @index}}
<img class="lazy" data-original="{{image2 param.bgimg q=60}}">
{{else}}
<img src="{{image2 param.bgimg q=60}}">
{{/isLazyLoad}}
{{/if}}
{{#component}}
{{#isEqualOr type 'link'}}
... ... @@ -24,7 +28,7 @@
{{#if modalImg}}
<div class="modal">
<span class="modal-close"></span>
<img class="modal-img" src="{{image2 modalImg q=60}}">
<img class="modal-img lazy" data-original="{{image2 modalImg q=60}}">
</div>
{{/if}}
</a>
... ... @@ -56,7 +60,7 @@
<div class="swiper-wrapper">
{{#list}}
<div class="swiper-slide" style="{{styleFormat this percent=1}}">
<img src="{{image2 src q=60}}">
<img class="lazy" data-original="{{image2 src q=60}}">
<a class="anchor" href="{{#if link}}{{link}}{{else}}javascript:void(0);{{/if}}" fp="{{getAnalysis ../../this @index}}"></a>
</div>
{{/list}}
... ... @@ -86,9 +90,9 @@
<div class="feature-product-info {{#if ../condition}}novisible{{/if}}">
<a class="first-part product-detail" href='{{producturl}}'>
<div class="product-detail-imgbox">
{{#if ../lefTopImg}}<img class="leftopimg" src="{{image2 ../lefTopImg q=60}}">{{/if}}
{{#if ../rigTopImg}}<img class="rigtopimg" src="{{image2 ../rigTopImg q=60}}">{{/if}}
<img class="product-detail-img" src="{{image2 productimg q=60}}">
{{#if ../lefTopImg}}<img class="leftopimg lazy" data-original="{{image2 ../lefTopImg q=60}}">{{/if}}
{{#if ../rigTopImg}}<img class="rigtopimg lazy" data-original="{{image2 ../rigTopImg q=60}}">{{/if}}
<img class="product-detail-img lazy" data-original="{{image2 productimg q=60}}">
</div>
{{#isEqualOr ../showPrdName '1'}}<p class="product-name">{{productname}}</p>{{/isEqualOr}}
<div class="product-detail-text">
... ... @@ -111,7 +115,7 @@
<div class="brand-div">
<span class="brand-name"{{#if ../fontColor}}style="color:{{../fontColor}};"{{/if}}>{{brandname}}</span>
</div>
<img class="brand-img" src="{{image2 ../brandImg q=60}}">
<img class="brand-img lazy" data-original="{{image2 ../brandImg q=60}}">
</a>
{{/if}}
</div>
... ...
var $ = require('yoho-jquery');
var lazyLoad = require('yoho-jquery-lazyload');
var Swiper = require('yoho-swiper');
global.jQuery = $;
... ... @@ -6,6 +7,8 @@ global.jQuery = $;
var isAndroid = /(Android)/i.test(navigator.userAgent);
var isWechat = /micromessenger/i.test(navigator.userAgent);
lazyLoad($('img.lazy'));
function swiperInit() {
$('.swiper-container').each(function() {
var opt = {
... ...
... ... @@ -35,6 +35,13 @@ module.exports = {
}
return JSON.stringify(fp);
},
isLazyLoad: function(type, index, opt){
if (type !== 'fix' && index > 8) { // 活动页中 不是浮动层及8张图后面的采用懒加载
return opt.fn(this); // eslint-disable-line
} else {
return opt.inverse(this); // eslint-disable-line
}
},
styleFormat: function(styleObj, opts) {
let style = '';
... ...