【问题标题】:LazyLoad Plugin is not willing to cooperate with my codeLazyLoad Plugin 不愿意配合我的代码
【发布时间】:2017-09-20 12:25:55
【问题描述】:

我正在练习使用插件(一开始是 LazyLoad)。 根据 GitHub 上包含的文档,我在 html 中的 Pexel 图片中插入了延迟加载类名称和数据原始属性。还添加了 jQuery sn-p。那么为什么它不起作用呢?

HTML:

<img class="lazyload" data-original="https://images.pexels.com/photos/566516/pexels-photo-566516.jpeg?w=940&h=650&auto=compress&cs=tinysrgb" src="https://images.pexels.com/photos/566516/pexels-photo-566516.jpeg?w=940&h=650&auto=compress&cs=tinysrgb" width="350px"height="250">

jQuery:

$(document).ready(function(){
    $("img.lazyload").lazyload();      
});

LazyLoad docs on GitHub
My code on Codepen

【问题讨论】:

  • 如果您尝试将它与相同的图像一起使用,它会如何工作。图片是第一个请求加载的。尝试使用不同的图片。

标签: javascript jquery html plugins


【解决方案1】:

请删除“src”属性值,这样也可以工作。 此链接可以完成您的工作fixed code

<img class="lazyload" data-src="https://images.pexels.com/photos/566516/pexels-photo-566516.jpeg?w=940&h=650&auto=compress&cs=tinysrgb" 

width="350px"height="250">

我做了以下更改

  1. 删除了“src”
  2. 将“data-original”重命名为“data-src”

注意:如果这适用于您的问题,请勾选此答案作为已回答。谢谢。

【讨论】:

  • @Ipradhap 感谢您的回答......但对我来说它像以前一样工作。图片“已经加载”,而我希望它在向下滚动期间从网站底部逐渐出现。
  • 使用开发者工具栏并查看有关延迟加载如何工作的图像。我给你的解决方案是延迟加载部分。在此处查看屏幕截图。 screencast.com/t/MJYmjNcBywu
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-14
  • 2011-01-24
相关资源
最近更新 更多