基本原理: 在可见范围内替换img标签的src为实际图片地址,实现图片的加载。未可见范围内的图片src为空,不进行图片的加载。
引用开源:
https://github.com/verlok/lazyload
官方说:性能优于jQuery的lazyload
LazyLoad is a fast, lightweight and flexible script for loading images only when they're about to enterthe viewport of a scrollable area, which supports the srcset
attribute andwith and takes best advantage from the progressive JPEGimage format
应用了渐进式图片,渐进式图片介绍见:
http://www.zhangxinxu.com/wordpress/2013/01/progressive-jpeg-image-and-so-on/
Name | Meaning | Default value |
| The container in which to start searching for elements, and from which to listen to the scroll event |
|
| The selector of the image elements inside the container |
|
| The distance out of the viewport, expressed in pixel, before which to start loading the images |
|
| The time that has to pass between one element parsing and the following, when fast scroll events occur |
|
| The name of the data attribute containing the original image source. The "data-" is automatically added. |
|
| The name of the data attribute containing the original image source set. The "data-" is automatically added. If you also need to add the |
|
| The class applied to the elements while the loading is in progress |
|
| The class applied to the elements when the loading is complete |
|
| Specifies whether the script has to consider invisible images or not |
|
| Specifies whether the script must show the images while they are loading. Set it to true when you use progressive JPEG format for your images. Note: to make the image visible while loading, you will have to avoid using the |
|
| A function to be called when an image was loaded. |
|
| A function to be called when the src of an image is set in the DOM. |
|
| A function to be called when an image was processed. |
|
| The URL of a placeholder image to be shown while the original image is loading. This option is ignored when the option | (A base64 encoded 1x1 transp. gif) |