Skip to content
This repository has been archived by the owner on Jun 7, 2024. It is now read-only.

Commit

Permalink
Fixed issue with infinite scrolling on mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
nienow committed Dec 13, 2023
1 parent 9c4b376 commit 77f46b5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
16 changes: 13 additions & 3 deletions src/components/Category.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const TEMPLATE = `
<div class="title-total"></div>
</div>
<div class="card-list"></div>
<div id="nextPage"></div>
`;

export class CategoryProjects extends HTMLElement {
Expand Down Expand Up @@ -53,11 +54,20 @@ export class CategoryProjects extends HTMLElement {
const percent = scrollTop / (scrollHeight - clientHeight);
const itemPercent = Math.round(percent * Math.min(index, projects.length) / projects.length * 100);
this.querySelector('.title-percent')!.innerHTML = itemPercent + '% viewed';
});

if (clientHeight + scrollTop >= scrollHeight - 50) {
renderProjects();
}
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
renderProjects();
}
});
}, {
root: null,
rootMargin: '0px',
threshold: 0.1
});
observer.observe(this.querySelector('#nextPage')!);
}
}

Expand Down
11 changes: 0 additions & 11 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ const twitterSVG = await fetch('https://storage.googleapis.com/randombits/images
<div>Brought to you by</div>
<div class="rb">Random Bits</div>
</div>
</a>
</a>

<div class="social-links">
Expand All @@ -65,16 +64,6 @@ const twitterSVG = await fetch('https://storage.googleapis.com/randombits/images
</div>

</div>
<!--<div class="footer-section">-->
<!-- <div class="footer-section-title">Docs</div>-->
<!--</div>-->
<!--<div class="footer-section">-->
<!-- <div class="footer-section-title">Contact</div>-->
<!-- <a href="https://twitter.com/RandomBitsDev">Twitter (X)</a>-->
<!-- <a href="https://discord.gg/drHPTNuk">Discord</a>-->
<!-- <a href="https://github.com/randombits-dev/micro-storage">Github</a>-->
<!--</div>-->
</div>

</footer>
</Layout>
Expand Down
9 changes: 8 additions & 1 deletion src/styles/global.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
html, body {
overflow-x: clip;
}

body {
font-family: 'League Spartan', sans-serif;
/*background: #eee;*/
color: #333;
margin: 0;
padding: 0;
Expand Down Expand Up @@ -212,3 +215,7 @@ button {
width: 32px;
height: 32px;
}

#nextPage {
height: 50px;
}

0 comments on commit 77f46b5

Please sign in to comment.