Go to comments ↓ Home » Blog

启用 Lazy Load jQuery 插件

Wordpress先吐槽一下,这几天主机的速度真不是一般的慢,打击更新欲望啊。
搬家的欲望再次萌生,可惜手头窘迫,再观望一下。

话说,最近抱着“既然加载了 jQuery,不多弄点功能,挺亏的”这种想法,折腾了些东西。比如之前的 Shadowbox
现在又发现了这个叫做 Lazy Load 的 jQuery 插件,它的作用是延迟加载页面中的图片,还能为添加渐显特效。

详细介绍和使用方法见 mg12 的这篇:《Lazy Load, 延迟加载图片的 jQuery 插件》
下面简单说下我的体验。

Lazy Load 的作用

Lazy Load 的作用简单来说就是:让网页元素加载顺序更加合理
网页代码的载入顺序是从上到下,如果评论区域有大量小图片(头像、表情、以及其他评论者信息),会导致侧栏的显示较慢,体验不好。
有了 Lazy Load ,在不可见区域的图片会被延迟加载,可以说在相当程度上提升了速度,在长页面尤为明显。
正好我比较喜欢 WP-UserAgent 这类型的插件,那就更需要这个了。

而且 Lazy Load 的 FadeIn 效果,让我们向评论区滚动的时候,下面的头像和表情等图片会以渐显的方式刷出来,感觉相当棒(自我感觉…)。
Lazy Load 的打包版体积还不足 2K,相当的小巧。

如何使用 Lazy Load

到作者页面去下载该 js,http://www.appelsiini.net/projects/lazyload

将 js 上传到服务器。
加载 jQuery,如果你博客已经使用了 jQuery,请跳过这一步。
在 wp 主题模板加入以下代码:

<script type="text/javascript" src="jquery.lazyload.js"></script>
<script type="text/javascript">jQuery(document).ready(
 function($){
          $("img").lazyload({
             placeholder : "images/grey.gif",
             effect      : "fadeIn"
          });
      });
  </script>

要注意 js 和图片文件的路径。
“img”是指对页面上所有图片都应用这个效果。你也可以用 CSS 选择器来制定,比如 #content img。
grey.gif 是指占位图片,可以到点此下载一个 1×1 象素的图片。

不想折腾的话可以使用个 WordPress 插件: jQuery Image Lazy Load WP ,我没有测试过。

» 转载请以超链接形式注明来源:A.shun Blog » 《启用 Lazy Load jQuery 插件》
» 本文链接地址:http://www.a-shun.com/archives/21363.html

» 本文采用 BY-NC-SA 协议进行授权。
» 建议通过 Rss( Google Reader | Feedburner | Feedsky )方式及时获取更新。
  1. 这插件效果的确不错。
    报告。访问速度很快~

    Firefox 3.6.3 Firefox 3.6.3 Windows 7 Windows 7
    #41
    @
  2. a-shun我启用了jQuery Image Lazy Load WP 这个插件,但是为什么在博客上没有效果呢??
    帮忙看看是什么问题吧。

    TheWorld Browser TheWorld Browser Windows XP Windows XP
    #42
    @
  3. 这种效果~不知道在ie浏览器中会卡不? :???:

    Google Chrome 6.0.427.0 Google Chrome 6.0.427.0 Windows XP Windows XP
    #43
    @
  4. 我的最近都好慢,等考试实习结束就去折腾

    ChromePlus 1.3.9.0 ChromePlus 1.3.9.0 Windows 7 Windows 7
    #44
    @
  5. 对主题做了滑动的效果不好,老看到图片空着……

    Google Chrome 5.0.375.70 Google Chrome 5.0.375.70 Windows 7 Windows 7
    #45
    @
  6. 那个插件我用了完全没有效果呢

    Firefox 3.5.9 Firefox 3.5.9 Windows XP Windows XP
    #46
    @
    • @junjun 囧。。插件我没用过。刚刚看了下你的源代码,好像js那里多了一个判断语句。

      还是建议直接用代码吧,消耗少很多。上面的代码直接贴在header,注意js的路径就好

      Opera 10.60 Opera 10.60 Windows XP Windows XP
    • @junjun 我之前加载那个插件也是没有任何效果。囧

      Google Chrome 8.0.552.0 Google Chrome 8.0.552.0 Windows 7 Windows 7
  7. :roll: :roll: :roll: :roll: 学习了。

    Google Chrome 6.0.401.1 Google Chrome 6.0.401.1 Windows XP Windows XP
    #47
    @
  8. 今天下定决心想弄这个js,
    但发现不会弄……

    一、js文件要上传到哪里呢?

    二、还有就是,mg12 那篇文章的这句——

    “并且在你的执行代码中加入下面语句”

    “你的执行代码”究竟是哪个文件的哪句代码呢……

    求教……

    Maxthon 2.0 Maxthon 2.0 Windows XP Windows XP
    #48
    @
  9. 第一次见到这个插件,是在一个UI设计师的网站看到,还以为是那哥们原创的呢,呵呵。

    Firefox 3.6.3 Firefox 3.6.3 Windows 7 Windows 7
    #49
    @
  10. 我想自己写个……我博客上没有jQuery,这个效果很好

    Google Chrome 5.0.366.2 Google Chrome 5.0.366.2 Windows XP Windows XP
    #50
    @
  11. 我现在没有你们这样拥有一个折腾的心了,我的解决方案就是大宽带,亚洲 100 GB+ 机房出口的。

    TheWorld Browser TheWorld Browser Windows 7 Windows 7
    #51
    @
  12. “在 wp 主题模板加入以下代码:” 下面的代码第一句的好像少了个t

    TheWorld Browser TheWorld Browser Windows 7 Windows 7
    #52
    @
  13. 被过滤掉了

    TheWorld Browser TheWorld Browser Windows 7 Windows 7
    #53
    @
  14. 《scrip》被过滤掉了

    TheWorld Browser TheWorld Browser Windows 7 Windows 7
    #54
    @
    • @nero 恩,误判、默认过滤这个。

      上次转义的时候多删了个t。谢谢提醒

      Opera 10.70 Opera 10.70 Windows XP Windows XP
  15. 被高亮的代码的第一行的用来闭合的script标签少写了一个t
    我看到楼上反应了这个问题却没有被修正。

    这个很不错,找了很久! :eek:

    Google Chrome 5.0.375.126 Google Chrome 5.0.375.126 Windows XP Windows XP
    #55
    @
  16. 我觉得你那个grey.gif没找到~~要不试试绝对位置。

    Firefox 3.6.6 Firefox 3.6.6 Windows 7 Windows 7
    #56
    @
    • @阿修 我用的就是绝对位置,不过贴代码的时候用那种,上面又说要注意嘛。

      相对路径的话,日志页面就杯具了- -

      Opera 10.70 Opera 10.70 Windows XP Windows XP
  17. 那个插件应该是有点问题的,我为了帮朋友弄测试过,会奇怪的突然停止工作。还是代码好用。

    Google Chrome 7.0.503.0 Google Chrome 7.0.503.0 Windows XP Windows XP
    #57
    @
  18. 啊顺 CSS选择器怎么指定呢?比如我就想让正文有这种效果

    Firefox 3.6.12 Firefox 3.6.12 Windows XP Windows XP
    #58
    @
  19. 装上插件了,感觉没什么变化

    Google Chrome 12.0.742.100 Google Chrome 12.0.742.100 Windows 7 Windows 7
    #59
    @
  20. 没看见你的网站加载这个插件,不过怎么还能看到该插件的效果-,- 关于该插件的效果 我有篇文章写了下我对它的效果测试的结果 可以看下 jQuery插件Lazy Load Plugin的效果讨论

    Google Chrome 13.0.782.112 Google Chrome 13.0.782.112 Windows XP Windows XP
    #60
    @
Leave a Reply

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

Trackbacks and Pingbacks: