...
|
...
|
@@ -19,19 +19,8 @@ function dataLazyLoad(doc) { |
|
|
|
|
|
// 工具方法 begin
|
|
|
var Util = {
|
|
|
getElementsByClassName: function(cls) {
|
|
|
if (doc.getElementsByClassName) {
|
|
|
return doc.getElementsByClassName(cls);
|
|
|
}
|
|
|
|
|
|
var o = doc.getElementsByTagName("*"),
|
|
|
rs = [];
|
|
|
|
|
|
for (var i = 0, t, len = o.length; i < len; i++) {
|
|
|
(t = o[i]) && ~t.className.indexOf(cls) && rs.push(t);
|
|
|
}
|
|
|
|
|
|
return rs;
|
|
|
getElements: function(cls) {
|
|
|
return $(cls).toArray();
|
|
|
},
|
|
|
addEvent: function(ele, type, fn) {
|
|
|
ele.attachEvent ? ele.attachEvent("on" + type, fn) : ele.addEventListener(type, fn, false);
|
...
|
...
|
@@ -79,7 +68,7 @@ function dataLazyLoad(doc) { |
|
|
fn: null, // {Function} scroll、resize、touchmove 所绑定方法,即为 pollTextareas()
|
|
|
|
|
|
evalScripts: function(code) {
|
|
|
var head = doc.getElementsByClassName("yoho-footer")[0],
|
|
|
var head = $(".yoho-footer")[0],
|
|
|
js = doc.createElement("script");
|
|
|
|
|
|
js.text = code;
|
...
|
...
|
@@ -188,7 +177,7 @@ function dataLazyLoad(doc) { |
|
|
var cls = config.cls;
|
|
|
this.threshold = config.threshold ? config.threshold : 0;
|
|
|
|
|
|
this.els = Array.prototype.slice.call(Util.getElementsByClassName(cls));
|
|
|
this.els = Array.prototype.slice.call(Util.getElements(cls));
|
|
|
this.fn = this.pollTextareas.bind(this);
|
|
|
|
|
|
this.fn();
|
...
|
...
|
@@ -206,7 +195,7 @@ module.exports = dataLazyLoad; |
|
|
/**
|
|
|
* demo
|
|
|
* datalazyload.init({
|
|
|
* cls: "datalazyload", // 需要延迟加载的类,即 textarea 的类名
|
|
|
* cls: ".datalazyload", // 需要延迟加载的类,即 textarea 的类名
|
|
|
* threshold: 100 // 距离底部多高,进行延迟加载的阈值
|
|
|
* });
|
|
|
*/ |
...
|
...
|
|