lazyload 是一个 jQuery 插件,它可以延迟加载长页面中的图片。 在浏览器可视区域外的图片不会被载入,直到用户将页面滚动到它们所在的位置。在包含很多大图片的长页面中,延迟加载图片可以加快页面加载速度,在某些情况下还可以帮助降低服务器负担。下面我们介绍一下如何使用此款 jQuery 插件在中实现图片延迟加载的效果。
1. 下载 lazyload 源代码,将下载的压缩包解压,复制 jquery.min.js 和 jquery.lazyload.min.js,放到自己的主题目录。
2. 切换到主题目录,打开header.PHP,引用 jquery.min.js和jquery.lazyload.min.js,详细的使用代码如下:
Crayon-5c891d521fe7b438215572" class="Crayon-Syntax Crayon-theme-classic Crayon-font-monaco Crayon-os-pc print-yes notranslate" data-settings=" minimize scroll-mouSEOver" style=" margin-top: 12px; margin-bottom: 12px; font-size: 12px !important; line-height: 15px !important;">
Crayon-toolbar" data-settings=" mouSEOver overlay hide delay" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-title">header.PHP
Crayon-tools" style="font-size: 12px !important;height: 18px !important; line-height: 18px !important;">Crayon-mixed-highlight" title="Contains Mixed Languages">
Crayon-button Crayon-nums-button" title="Toggle Line Numbers">
Crayon-button-icon">
Crayon-button Crayon-plain-button" title="Toggle Plain Code">
Crayon-button-icon">
Crayon-button Crayon-wrap-button" title="Toggle Line Wrap">
Crayon-button-icon">
Crayon-button Crayon-expand-button" title="Expand Code">
Crayon-button-icon">
Crayon-button Crayon-copy-button" title="Copy">
Crayon-button-icon">
Crayon-button Crayon-popup-button" title="Open Code In New Window">
Crayon-button-icon">
Crayon-info" style="min-height: 16.8px !important; line-height: 16.8px !important;">
Crayon-plain-wrap">
Crayon-main" style="">Crayon-table">
Crayon-nums " data-settings="show"> Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;"> Crayon-num" data-line="Crayon-5c891d521fe7b438215572-1">1 Crayon-num" data-line="Crayon-5c891d521fe7b438215572-3">3 Crayon-num" data-line="Crayon-5c891d521fe7b438215572-5">5 Crayon-num" data-line="Crayon-5c891d521fe7b438215572-7">7 Crayon-num" data-line="Crayon-5c891d521fe7b438215572-9">9 | Crayon-code">
Crayon-nums " data-settings="show"> Crayon-nums-content" style="font-size: 12px !important; line-height: 15px !important;"> Crayon-num" data-line="Crayon-5c891d521fe8e597106700-1">1 Crayon-num" data-line="Crayon-5c891d521fe8e597106700-3">3 Crayon-num" data-line="Crayon-5c891d521fe8e597106700-5">5 Crayon-num" data-line="Crayon-5c891d521fe8e597106700-7">7 | Crayon-code">