1
0
mirror of https://github.com/Pomax/BezierInfo-2.git synced 2025-08-29 11:10:38 +02:00

improved lazy loading

This commit is contained in:
Pomax
2020-09-13 13:18:15 -07:00
parent a626c2c8cb
commit c0a1207d67
27 changed files with 163 additions and 208 deletions

View File

@@ -1,17 +1,13 @@
const comments = document.getElementById(`disqus_thread`);
document.addEventListener("scroll", scrollHandler, { passive: true });
function scrollHandler() {
var bbox = comments.getBoundingClientRect();
var top = bbox.top;
var limit = window.innerHeight;
if (top < limit) {
loadDisqus();
}
}
new IntersectionObserver(function (entries) {
entries.forEach((entry) => {
if (entry.isIntersecting) {
loadDisqus();
}
});
}).observe(document.getElementById(`disqus_thread`));
let loadDisqus = () => {
loadDisqus = () => {};
console.log(`loading Disqus comments`);
globalThis.disqus_config = function () {
@@ -24,9 +20,4 @@ let loadDisqus = () => {
script.async = true;
script.setAttribute("data-timestamp", Date.now());
document.head.appendChild(script);
loadDisqus = () => {};
document.removeEventListener("scroll", scrollHandler);
};
scrollHandler();