Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 [Mobile] Ever so slightly improved scrolling #65

Merged
merged 3 commits into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/components/Navigation.astro
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ const {id, items = []} = Astro.props;
z-index: calc(var(--index-thermosphere) + 1);
bottom: var(--nav-list-bottom);
right: 0;
display: grid;
justify-items: end;

&[aria-hidden='false'] {
width: auto;
Expand All @@ -101,8 +103,6 @@ const {id, items = []} = Astro.props;
}

.Item {
float: right;
clear: both;
transition: translate var(--speed) var(--ease);
/* Stagger animation offset */
transition-delay: calc(var(--speed-fastest) * var(--nav-item-index));
Expand Down
16 changes: 10 additions & 6 deletions src/scripts/Portfolio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class Portfolio {
#scrollHeight = 0;
#sectionHeight = 0;

#isTicking = false;
#rafTicking = false;

// TODO: There is a bug in Firefox Mobile that causes the "URL bar" to
// re-appear everytime the url is updated (ex: via replaceState). I am
Expand Down Expand Up @@ -106,13 +106,17 @@ export class Portfolio {
}

teardown() {
window.removeEventListener('hashchange', this.#runAllUpdates);
this.scroller.removeEventListener('scroll', this.#handleScroll);
window.removeEventListener('resize', this.#handleResize);

cancelAnimationFrame(this.#rafId);
}

#registerEventListeners() {
// Required alongside `handleScroll` for anchor tags.
window.addEventListener('hashchange', this.#runAllUpdates, false);

// `passive` may not actually make sense for `scroll` events.
this.scroller.addEventListener('scroll', this.#handleScroll, {
passive: true,
Expand Down Expand Up @@ -172,18 +176,18 @@ export class Portfolio {
);
}

#rafCallback = () => {
#runAllUpdates = () => {
this.#updateIndex();
this.#updatePortfolioColor();

this.#isTicking = false;
this.#rafTicking = false;
};

#handleScroll = () => {
if (this.#isTicking) return;
if (this.#rafTicking) return;

this.#rafId = requestAnimationFrame(this.#rafCallback);
this.#isTicking = true;
this.#rafId = requestAnimationFrame(this.#runAllUpdates);
this.#rafTicking = true;

this.#onScroll?.({
currentIndex: this.currentIndex,
Expand Down
19 changes: 8 additions & 11 deletions src/styles/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -87,26 +87,23 @@ body {
cursor: url('../assets/svg/cursors/CursorAuto.svg'), auto;
}

/* --- Smooth scroll + snapping --- */
/* --- Scroll snapping --- */

html {
/*
It is possible that Safari may require this to be
added to the <body /> as well.
Scroll snapping creates many problems on iOS when used in combination
with `100vh`, so we are enabling this only for larger devices.
*/
scroll-snap-type: y mandatory;

/*
Ideally, we use `proximity` everywhere...
but iOS scrolling just feels janky when `proximity` is used.
*/
@media (--min-tablet) {
@media (--min-desktop) {
scroll-snap-type: y proximity;
}
}

.section {
scroll-snap-align: start;
/* See note above about iOS issues */
@media (--min-desktop) {
scroll-snap-align: start;
}
}

/* --- Components --- */
Expand Down