Добавил автопрогрузку
This commit is contained in:
parent
b7d40913c6
commit
9c2bcef8b1
1 changed files with 22 additions and 8 deletions
30
js/main.js
30
js/main.js
|
@ -93,20 +93,34 @@ async function verseToGrid(i) {
|
||||||
div.onclick = () => window.open(`/${i}`, '_self')
|
div.onclick = () => window.open(`/${i}`, '_self')
|
||||||
div.classList.add(verse.GENRE)
|
div.classList.add(verse.GENRE)
|
||||||
div.innerHTML = `<h2>${verse.TITLE}</h2><a href="/${author.LOGIN}">${author.NAME} ${author.SUBNAME}</a><pre>${verse.PRE}</pre>`
|
div.innerHTML = `<h2>${verse.TITLE}</h2><a href="/${author.LOGIN}">${author.NAME} ${author.SUBNAME}</a><pre>${verse.PRE}</pre>`
|
||||||
div.style.display = 'flow-root'
|
div.style.display = 'block'
|
||||||
|
return div
|
||||||
}
|
}
|
||||||
|
|
||||||
function addVersePart(part = 0) {
|
let Part = 0
|
||||||
fetchJSON(`/api/versepart/${part}`)
|
|
||||||
|
function addVersePart() {
|
||||||
|
fetchJSON(`/api/versepart/${Part++}`)
|
||||||
.then(result => {
|
.then(result => {
|
||||||
if (result) {
|
if (result) {
|
||||||
let arr = []
|
const arr = Object.keys(result)
|
||||||
for (v in result)
|
const first = arr[0]
|
||||||
arr.push(v)
|
|
||||||
arr.reverse()
|
arr.reverse()
|
||||||
arr.forEach(i => {
|
arr.forEach(async i => {
|
||||||
cacheVerse[i] = result[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)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue