我们正在尝试在https://berkshireblanket.com上实现(https://github.com/aFarkas/lazysizes/tree/master)。
但在遵循所有方向后,实现将不起作用。当我使用DevTools运行检查时,它输出为false:
typeof($("img").lazyload) === "function"我不知所措,我不确定我们是在脚本中还是在HTML中遗漏了什么。
下面是我们的HTML,展示它目前是如何实现的:

<div class="product-main-images {% if section.settings.thumbnails == 'bottom' %}desktop-12{% else %}desktop-10{% endif %} tablet-6 mobile-3" tabindex="0">
<div class="product-image-container" style="padding-bottom: {{ product_image_box_ratio_max }};" >
{% for image in product.images %}
{% assign image_box_ratio = image.height | append: ".0" | times: 1 | divided_by: image.width | times: 100 | append: "%" %}
{% assign img_url = image | img_url: '1x1' | replace: '_1x1.', '_{width}x.' %}
<div class="product-main-image {% if forloop.first %}selected{% endif %}" data-image-id="{{ image.id }}">
<a class="product-fancybox" rel="product-images" href="{{ image | img_url: '2400x' }}" tabindex="-1">
<img id="{{ product.id }}" class="product__image lazyload"
src="{{ image | product_img_url: '300x' }}"
data-src="{{ img_url }}"
data-sizes="auto"
data-zoom-src="{{ image | img_url: '2400x' }}"
alt="{{ image.alt | escape }}">
</a>
<noscript>
<img id="{{ product.id }}" class="product-main-image lazyload" src="{{ featured_image | product_img_url: '800x' }}" alt='{{ image.alt | escape }}'/>
</noscript>
</div>
{% endfor %}
</div>
</div>如果有任何帮助,我将不胜感激!
如果我能澄清什么,请告诉我,或者提供我们当前实现的更多示例。
谢谢!
发布于 2019-12-18 04:18:43
您可能需要将src更改为data-src
<img id="{{ product.id }}" class="product-main-image lazyload" data-src="{{ featured_image | product_img_url: '800x' }}" alt='{{ image.alt | escape }}'/>发布于 2021-01-17 15:48:24
安装lazysize,然后将类"lazyload“添加到所有图像和iframe中,并在img标签中确保将"src”更改为"data-src“
https://stackoverflow.com/questions/58713323
复制相似问题