首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Lazysizes.min.js实现不起作用

Lazysizes.min.js实现不起作用
EN

Stack Overflow用户
提问于 2019-11-05 22:20:19
回答 2查看 2.6K关注 0票数 2

我们正在尝试在https://berkshireblanket.com上实现(https://github.com/aFarkas/lazysizes/tree/master)。

但在遵循所有方向后,实现将不起作用。当我使用DevTools运行检查时,它输出为false:

代码语言:javascript
复制
typeof($("img").lazyload) === "function"

我不知所措,我不确定我们是在脚本中还是在HTML中遗漏了什么。

下面是我们的HTML,展示它目前是如何实现的:

代码语言:javascript
复制
<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>

如果有任何帮助,我将不胜感激!

如果我能澄清什么,请告诉我,或者提供我们当前实现的更多示例。

谢谢!

EN

回答 2

Stack Overflow用户

发布于 2019-12-18 04:18:43

您可能需要将src更改为data-src

代码语言:javascript
复制
<img id="{{ product.id }}" class="product-main-image lazyload" data-src="{{ featured_image | product_img_url: '800x' }}" alt='{{ image.alt | escape }}'/>
票数 1
EN

Stack Overflow用户

发布于 2021-01-17 15:48:24

安装lazysize,然后将类"lazyload“添加到所有图像和iframe中,并在img标签中确保将"src”更改为"data-src“

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58713323

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档