Commit 6ad327b9 by liumengfei

恢复图片列表图片加载方式

parent d1d35948
......@@ -120,9 +120,9 @@ $_helper = $block->getData('outputHelper');
<?php
$productImageRaw = $imageHelper->init($_product, $imageDisplayArea)->setImageFile($productImage->getFile())->resize($productImage->getWidth(),$productImage->getHeight())->getUrl();
?>
<img class="product-image-photo" style="background-color: #F0F0F0;border: none;" data-src="<?= $productImageRaw ?>" loading="lazy" width="<?= $productImage->getWidth() ?>px" height="<?= $productImage->getHeight() ?>px" />
<img class="product-image-photo" style="background-color: #F0F0F0;border: none;" src="<?= $productImageRaw ?>" loading="lazy" width="<?= $productImage->getWidth() ?>px" height="<?= $productImage->getHeight() ?>px" />
<?php if ($hoverImg): ?>
<img class="hoverImg" width="<?= $productImage->getWidth() ?>px" height="<?= $productImage->getHeight() ?>px" data-src="<?= $hoverImg ?>" loading="lazy" />
<img class="hoverImg" width="<?= $productImage->getWidth() ?>px" height="<?= $productImage->getHeight() ?>px" src="<?= $hoverImg ?>" loading="lazy" />
<?php endif; ?>
</a>
<div class="product details product-item-details">
......@@ -237,31 +237,4 @@ $_helper = $block->getData('outputHelper');
'item' : <?= json_encode($items, true) ?>
})
</script>
<script>
const imgs = document.getElementsByTagName("img");
const viewHeight =
window.innerHeight || document.documentElement.clientHeight;
let num = 0;
function lazyload() {
for (let i = num; i < imgs.length; i++) {
let distance = viewHeight - imgs[i].getBoundingClientRect().top;
if (distance >= 0) {
imgs[i].src = imgs[i].getAttribute("data-src");
num = i + 1;
}
}
}
function debounce(fn, delay = 100) {
let timer = null;
return function (...args) {
if (timer) clearTimeout(timer);
timer = setTimeout(() => {
fn.call(this, args);
}, delay);
};
}
window.onload = lazyload;
window.addEventListener("scroll", debounce(lazyload, 100), false);
</script>
<?php endif; ?>
......@@ -25,12 +25,11 @@ $logoHeight = $logoSizeResolver !== null && $logoSizeResolver->getHeight()
href="<?= $block->escapeUrl($block->getUrl('')) ?>"
title="<?= $block->escapeHtmlAttr($storeName) ?>"
aria-label="store logo">
<img class="site-logo" data-src="<?= $block->escapeUrl($block->getLogoSrc()) ?>" src="<?= $block->escapeUrl($block->getLogoSrc()) ?>"
<img class="site-logo" src="<?= $block->escapeUrl($block->getLogoSrc()) ?>"
title="<?= $block->escapeHtmlAttr($block->getLogoAlt()) ?>"
alt="<?= $block->escapeHtmlAttr($block->getLogoAlt()) ?>"
<?= $logoWidth ? 'width="' . $block->escapeHtmlAttr($logoWidth) . '"' : '' ?>
<?= $logoHeight ? 'height="' . $block->escapeHtmlAttr($logoHeight) . '"' : '' ?>
loading="lazy" />
<?= $logoHeight ? 'height="' . $block->escapeHtmlAttr($logoHeight) . '"' : '' ?> />
<?php if ($block->getRequest()->getModuleName() == "checkout") { ?>
<span class="secure-span">
<span class="cut-span" >
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment