Authored by 郭成尧

lazyload-modified

... ... @@ -9,7 +9,7 @@ global.jQuery = $;
let isAndroid = /(Android)/i.test(navigator.userAgent);
let isWechat = /micromessenger/i.test(navigator.userAgent);
lazyLoad($('img.lazy'), {q: 75});
lazyLoad($('img.lazy'), {q: 95});
function swiperInit() {
$('.swiper-container').each(function() {
... ...
... ... @@ -4,6 +4,8 @@ const $ = require('yoho-jquery');
require('jquery-lazyload');
const defaultQuality = 60;
/**
* 图片链接处理
*/
... ... @@ -20,14 +22,33 @@ const imgSrcHandle = (imgUrl, params) => {
if (window.supportWebp) {
url += `?imageView2/0/interlace/1/format/webp/q/${params.q}`;
} else {
let extQuery = params.q === 75 ? '?imageslim' : `?imageView2/0/interlace/1/q/${params.q}`;
let extQuery = params.q === defaultQuality ? '?imageslim' : `?imageView2/0/interlace/1/q/${params.q}`;
url += extQuery;
}
return url;
} else {
return imgUrl;
imgUrl = url;
} else if (/imageView2/.test(query)) {
if (!/\/q\/\d+/.test(imgUrl)) {
imgUrl += `/q/${params.q}`;
} else {
imgUrl = imgUrl.replace(/\/q\/\d+/g, '/q/' + params.q);
}
if (window.supportWebp && !/format\//.test(imgUrl)) {
imgUrl += '/format/webp';
}
} else if (/imageMogr2/.test(query)) {
if (!/\/quality\/\d+/.test(imgUrl)) {
imgUrl += `/quality/${params.q}`;
} else {
imgUrl = imgUrl.replace(/\/quality\/\d+/g, '/quality/' + params.q);
}
if (window.supportWebp && !/format\//.test(imgUrl)) {
imgUrl += '/format/webp';
}
}
return imgUrl;
};
/**
... ... @@ -39,7 +60,7 @@ const rawLazyload = (selector, options) => {
threshold: 700
};
let imgParams = {
q: options && options.q || 75
q: options && options.q || defaultQuality
};
if (selector instanceof $) {
... ...
... ... @@ -15,8 +15,11 @@ let $indexGoodsContaniner = $('#indexGoodsContainer');
let $collect = $('#collect');
const shopId = $('#shopId').val();
const lazyLoadParams = {
q: 75
};
lazyLoad($('.lazy'));
lazyLoad($('.lazy'), lazyLoadParams);
/**
* 异步检测是否已经收藏
... ... @@ -93,7 +96,7 @@ $.each($goodsContainer, function(index, elem) {
success: function(result) {
let $result = $(result);
lazyLoad($result.find('img[class=lazy]'));
lazyLoad($result.find('img[class=lazy]'), lazyLoadParams);
$(elem).html($result);
}
});
... ... @@ -116,7 +119,7 @@ $.ajax({
success: function(result) {
let $result = $(result);
lazyLoad($result.find('img[class=lazy]'));
lazyLoad($result.find('img[class=lazy]'), lazyLoadParams);
$indexGoodsContaniner.find('.container').html($result);
}
});
... ...