Browse Source

fix issue #83 (Image Inside a Scrollable div Would not be Loaded)

pull/84/head
ethonchan 10 years ago
parent
commit
86e01ee8bb
  1. 39
      src/echo.js

39
src/echo.js

@ -1,20 +1,12 @@
(function (root, factory) { (function() {
if (typeof define === 'function' && define.amd) {
define(function() {
return factory(root);
});
} else if (typeof exports === 'object') {
module.exports = factory;
} else {
root.echo = factory(root);
}
})(this, function (root) {
'use strict'; 'use strict';
var echo = {}; var echo = {};
var _global = this || (0,eval)('this');
var root = {};
var callback = function () {}; var callback = function () {
};
var offset, poll, delay, useDebounce, unload; var offset, poll, delay, useDebounce, unload;
@ -32,11 +24,11 @@
}; };
var debounceOrThrottle = function () { var debounceOrThrottle = function () {
if(!useDebounce && !!poll) { if (!useDebounce && !!poll) {
return; return;
} }
clearTimeout(poll); clearTimeout(poll);
poll = setTimeout(function(){ poll = setTimeout(function () {
echo.render(); echo.render();
poll = null; poll = null;
}, delay); }, delay);
@ -44,7 +36,7 @@
echo.init = function (opts) { echo.init = function (opts) {
opts = opts || {}; opts = opts || {};
root = opts.viewport || this || (0,eval)('this'); root = opts.viewport || _global;
var offsetAll = opts.offset || 0; var offsetAll = opts.offset || 0;
var offsetVertical = opts.offsetVertical || offsetAll; var offsetVertical = opts.offsetVertical || offsetAll;
var offsetHorizontal = opts.offsetHorizontal || offsetAll; var offsetHorizontal = opts.offsetHorizontal || offsetAll;
@ -78,8 +70,8 @@
var view = { var view = {
l: 0 - offset.l, l: 0 - offset.l,
t: 0 - offset.t, t: 0 - offset.t,
b: (root.innerHeight || document.documentElement.clientHeight) + offset.b, b: (root.innerHeight || root.clientHeight) + offset.b,
r: (root.innerWidth || document.documentElement.clientWidth) + offset.r r: (root.innerWidth || root.clientWidth) + offset.r
}; };
for (var i = 0; i < length; i++) { for (var i = 0; i < length; i++) {
elem = nodes[i]; elem = nodes[i];
@ -130,6 +122,13 @@
clearTimeout(poll); clearTimeout(poll);
}; };
if ((typeof module !== "undefined" && module !== null) && module.exports) {
module.exports = echo;
} else if (typeof define === 'function') {
define(function() {
return echo; return echo;
});
}); } else {
root.echo = echo;
}
}());
Loading…
Cancel
Save