forked from hamid/intersection-observer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinfinite-scrolling.js
More file actions
28 lines (25 loc) · 802 Bytes
/
Copy pathinfinite-scrolling.js
File metadata and controls
28 lines (25 loc) · 802 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
document.addEventListener('DOMContentLoaded', () => {
const sentinel = document.getElementById('sentinel');
let isLoading = false;
const loadMoreContent = () => {
// Simulate asynchronous content loading
isLoading = true;
setTimeout(() => {
const contentContainer = document.getElementById('content-container');
for (let i = 0; i < 10; i++) {
const newItem = document.createElement('div');
newItem.textContent = 'More content ' + i;
contentContainer.appendChild(newItem);
}
isLoading = false;
}, 1000);
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting && !isLoading) {
loadMoreContent();
}
});
});
observer.observe(sentinel);
});