我需要消除图像渲染阻塞,为此我使用了这个小脚本
<img data-src>
$('img').each(function() {
$(this).attr('src', $(this).data('src'));
});
对所有浏览器都有好处或者最好使用这个插件https://plugins.jquery.com/lazyload/ ?
最佳答案
您可以添加此 CSS 规则以避免出现损坏的图像图标:
img[src=''],
img:not([src]) {
opacity: 0;
}
这样,没有 src 的图片将不会显示。
关于javascript - 延迟加载的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45610925/