Update docs

This commit is contained in:
Alan Grainger
2025-01-10 14:17:54 +08:00
parent 3ab84b00c3
commit 77d23beb26
+14 -3
View File
@@ -4,6 +4,9 @@ class LGallery {
element element
index = 0 index = 0
/**
* Create a lightGallery instance and populate it with the first page of gallery items
*/
init (params = {}) { init (params = {}) {
// Create the lightGallery instance // Create the lightGallery instance
this.element = document.getElementById('lightgallery') this.element = document.getElementById('lightgallery')
@@ -35,6 +38,9 @@ class LGallery {
lgallery.handleScroll() lgallery.handleScroll()
} }
/**
* Listen for scroll events and load more gallery items
*/
handleScroll () { handleScroll () {
const rect = lgallery.element.getBoundingClientRect() const rect = lgallery.element.getBoundingClientRect()
const scrollPosition = Math.max(0, rect.bottom - window.innerHeight) const scrollPosition = Math.max(0, rect.bottom - window.innerHeight)
@@ -45,10 +51,16 @@ class LGallery {
} }
} }
/**
* Load more gallery items as per lightGallery docs
* https://www.lightgalleryjs.com/demos/infinite-scrolling/
*/
loadMoreItems () { loadMoreItems () {
const numberOfItems = 80 const numberOfItems = 2
if (this.index < this.items.length) { if (this.index < this.items.length) {
// Append thumbnails this.index += numberOfItems
// Append new thumbnails
this.items this.items
.slice(this.index, this.index + numberOfItems) .slice(this.index, this.index + numberOfItems)
.forEach(item => { .forEach(item => {
@@ -63,7 +75,6 @@ class LGallery {
} }
}) })
this.lightGallery.refresh() this.lightGallery.refresh()
this.index += numberOfItems
} }
} }
} }