diff --git a/js/main.js b/js/main.js index cd303c0..215fe17 100644 --- a/js/main.js +++ b/js/main.js @@ -93,20 +93,34 @@ async function verseToGrid(i) { div.onclick = () => window.open(`/${i}`, '_self') div.classList.add(verse.GENRE) div.innerHTML = `
${verse.PRE}` - div.style.display = 'flow-root' + div.style.display = 'block' + return div } -function addVersePart(part = 0) { - fetchJSON(`/api/versepart/${part}`) +let Part = 0 + +function addVersePart() { + fetchJSON(`/api/versepart/${Part++}`) .then(result => { if (result) { - let arr = [] - for (v in result) - arr.push(v) + const arr = Object.keys(result) + const first = arr[0] arr.reverse() - arr.forEach(i => { + arr.forEach(async i => { cacheVerse[i] = result[i] - verseToGrid(i) + const div = await verseToGrid(i) + if (i == first) { + const observer = new IntersectionObserver(entries => { + entries.forEach(entry => { + if (entry.isIntersecting) { + addVersePart() + console.log(2) + observer.unobserve(entry.target) + } + }) + }) + observer.observe(div) + } }) } })