我正在尝试使用延迟加载和图片填充来工作。
如果我只使用基本图像,延迟加载本身就可以工作:
<img class=lazyload data-srcset="http://placehold.it/301x301">
如果我检查 Chrome 中的网络选项卡,我可以看到图像是在红线之后加载的,所以一切都很好:
现在我添加了一个<picture>
元素与我的响应式图像并尝试加载它也很懒:
<picture>
<!--[if IE 9]><video style="display: none;"><![endif]-->
<source srcset="http://placehold.it/1370x301 1x, http://placehold.it/2055x450 2x" media="(min-width: 1024px)" />
<source srcset="http://placehold.it/1023x300 1x, http://placehold.it/1534x450 2x" media="(min-width: 768px)" />
<source srcset="http://placehold.it/767x300 1x, http://placehold.it/1151x450 2x" media="(min-width: 384px)" />
<!--[if IE 9]></video><![endif]-->
<img
class="lazyload"
style="width: 100%; max-width: 100%;"
alt="Sample pic"
data-srcset="http://placehold.it/383x300 1x, http://placehold.it/575x450 2x"
/>
</picture>
Unfortunately, this image is not lazyloaded but loaded directly:
我还尝试在图片元素图像中仅使用一个 src,但这没有什么区别。
根据lazysizes文档,应该可以使其一起工作,所以我想我只是错过了一个小细节?
更新:Lazysizes 和 Picturefill 均已加载到<head>
.