Skip to content

Commit

Permalink
✨ [Page] Bring back scroll snapping but properly this time
Browse files Browse the repository at this point in the history
  • Loading branch information
beefchimi committed Jul 26, 2024
1 parent a8d033d commit 8c05abd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
8 changes: 8 additions & 0 deletions src/scripts/Portfolio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ export class Portfolio {

#isTicking = 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
// simply disabling this behaviour for now... but I may need to do a
// user-agent sniff in order to work around it.
static SUPPORT_URL_UPDATES = false;

constructor(selectors?: Selectors) {
this.#selector = {
cssColorProp: selectors?.cssColorProp || CSS_PORTFOLIO_COLOR_PROP,
Expand Down Expand Up @@ -111,6 +117,8 @@ export class Portfolio {
}

#updateUrlHash() {
if (!Portfolio.SUPPORT_URL_UPDATES) return;

const urlHash = this.#index === 0 ? ' ' : `#${sections[this.#index].id}`;

// Passing an empty `string` as `urlHash` will NOT remove any previous `hash`,
Expand Down
46 changes: 19 additions & 27 deletions src/styles/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -88,34 +88,37 @@ body {
}

/* --- Smooth scroll + snapping --- */
/* Disabled because it breaks "dynamic chrome" behaviour on iOS */

/*
html,
body {
height: 100svh;
overflow: hidden;
}
html {
/*
It is possible that Safari may require this to be
added to the <body /> as well.
*/
scroll-snap-type: y mandatory;

main {
height: 100svh;
overflow: scroll;
scroll-snap-points-y: repeat(100svh);
scroll-snap-type: y proximity;
scroll-behavior: smooth;
/*
Ideally, we use `proximity` everywhere...
but iOS scrolling just feels janky when `proximity` is used.
*/
@media (--min-tablet) {
scroll-snap-type: y proximity;
}
}

.section {
position: relative;
scroll-snap-align: start;
}
*/

/* --- Components --- */

.section {
width: 100dvw;
height: 100svh;
/*
`lvh` appears to behave differently between various Mobile browsers...
but the intention is to always use the "largest viewport height".
Using a "dynamic" height leads to a lot of scroll jank.
*/
height: 100lvh;
background-repeat: no-repeat;
background-position: center center;
background-size: cover;
Expand All @@ -126,17 +129,6 @@ main {
overflow: hidden;
}

/*
TODO: Experiment with this when Safari has better support.
At the moment, the site in "web app view" does not stretch
the full height of the viewport (likely because of `svh`).
*/
/*
.section:fullscreen {
height: 100dvh;
}
*/

.section-interior {
display: grid;
gap: var(--space-looser);
Expand Down

0 comments on commit 8c05abd

Please sign in to comment.