lazyload.js
1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* lazyload
* @author: xuqi(qi.xu@yoho.cn)
* @date: 2015/6/25
*/
var $ = require('yoho.jquery');
require('./lib/jquery.lazyload.js');
/**
* 为指定imgs添加lazyload效果,未指定imgs则为所有img.lazy添加lazyload效果
* @params imgs lazyload的图片
* @params options lazyload效果选项
*/
module.exports = function(imgs, options) {
var setting = {
effect : 'fadeIn',
effect_speed: 10,
placeholder: 'data:image/gif;base64,R0lGODlhAQABAJEAAAAAAP///93d3f///yH5BAEAAAMALAAAAAABAAEAAAICVAEAOw==',
skip_invisible: false
}, $imgs, argsLength = arguments.length;
//分解参数
(function seperateOptions() {
switch (argsLength) {
case 0:
$imgs = $('img.lazy');
break;
case 1:
if (imgs instanceof $) {
//img
$imgs = imgs;
} else {
$imgs = $('img.lazy');
$.extend(setting, imgs);
}
break;
case 2:
$imgs = imgs;
setting = $.extend(setting, options);
break;
}
}());
$imgs.lazyload(setting);
};