Добавил автопрогрузку
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.classList.add(verse.GENRE)
|
||||
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) {
|
||||
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)
|
||||
}
|
||||
})
|
||||
}
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue