"));
loadMore();
};
xhr.onerror = function() {
isLoading = false;
from -= imgCount;
loadMore();
};
xhr.open("GET", url);
xhr.send();
}
function appendTo(elem, data) {
if (!elem || typeof elem.appendChild != "function") return;
var d = document.createElement("div");
d.innerHTML = data;
while (d.firstChild) {
elem.appendChild(d.firstChild);
}
}
function fn() {
if (!window.document) {
return requestAnimationFrame(fn);
}
if (!isLoading) {
loadMore();
}
if (!centerContent) {
leftContent = document.querySelector(leftContentSelector);
centerContent = document.querySelector(centerContentSelector);
rightContent = document.querySelector(rightContentSelector);
if (!centerContent) return requestAnimationFrame(fn);
}
var wWidth = window.innerWidth;
var lRect = (leftContent ? leftContent.getBoundingClientRect() : {bottom: -1000, height: 0});
var cRect = centerContent.getBoundingClientRect();
var rRect = (rightContent ? rightContent.getBoundingClientRect() : {bottom: -1000, height: 0});
var pos = Math.max(
(lRect.height > 0 ? (window.innerHeight - lRect.bottom) : -1000),
(cRect.height > 0 ? (window.innerHeight - cRect.bottom) : -1000),
(rRect.height > 0 ? (window.innerHeight - rRect.bottom) : -1000)
);
if (pos > -100 && buffer.length > 0) {
var data = buffer.splice(0, 1)[0];
appendTo(leftContent, data[0]);
appendTo(centerContent, data[1]);
appendTo(rightContent, data[2]);
return setTimeout(function () {
requestAnimationFrame(fn);
}, 250);
} else {
return requestAnimationFrame(fn);
}
}
requestAnimationFrame(fn);
})();
Comments