Skip to content

Commit 9a2b15b

Browse files
Bikram GoleBikram Gole
authored andcommitted
Improve bottom rail scrolling
1 parent 25405c8 commit 9a2b15b

2 files changed

Lines changed: 34 additions & 2 deletions

File tree

script.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ if (backToTopBtn) {
5555
}
5656

5757
const sectionRailLinks = Array.from(document.querySelectorAll(".section-rail a[data-section]"));
58+
const sectionRail = document.querySelector(".section-rail");
5859
const railSections = sectionRailLinks
5960
.map((link) => {
6061
const id = link.dataset.section;
@@ -66,6 +67,25 @@ const railSections = sectionRailLinks
6667

6768
let activeRailId = null;
6869

70+
if (sectionRail) {
71+
const updateRailOverflow = () => {
72+
sectionRail.classList.toggle("rail-scrollable", sectionRail.scrollWidth > sectionRail.clientWidth + 1);
73+
};
74+
updateRailOverflow();
75+
window.addEventListener("resize", updateRailOverflow);
76+
sectionRail.addEventListener("scroll", updateRailOverflow, { passive: true });
77+
sectionRail.addEventListener(
78+
"wheel",
79+
(event) => {
80+
if (!sectionRail.classList.contains("rail-scrollable")) return;
81+
if (Math.abs(event.deltaY) <= Math.abs(event.deltaX)) return;
82+
sectionRail.scrollLeft += event.deltaY;
83+
event.preventDefault();
84+
},
85+
{ passive: false }
86+
);
87+
}
88+
6989
function setActiveRail(id) {
7090
if (!id || id === activeRailId) return;
7191
activeRailId = id;

styles.css

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ body {
264264
font-family: "Space Grotesk", sans-serif;
265265
color: var(--ink);
266266
min-height: 100dvh;
267-
padding-bottom: 1.55rem;
267+
padding-bottom: calc(1.55rem + env(safe-area-inset-bottom));
268268
background-color: var(--bg-0);
269269
background:
270270
radial-gradient(920px 360px at 14% -12%, rgba(51, 111, 203, 0.36), transparent 62%),
@@ -975,7 +975,7 @@ nav a.active {
975975
display: flex;
976976
gap: 0.38rem;
977977
z-index: 22;
978-
pointer-events: none;
978+
pointer-events: auto;
979979
padding: 0.28rem 0.4rem;
980980
border-radius: 999px;
981981
background: rgba(6, 12, 26, 0.65);
@@ -984,6 +984,17 @@ nav a.active {
984984
box-shadow: 0 8px 20px rgba(4, 10, 20, 0.28);
985985
max-width: min(92vw, 980px);
986986
overflow-x: auto;
987+
overflow-y: hidden;
988+
scroll-snap-type: x proximity;
989+
scroll-padding: 0.6rem;
990+
overscroll-behavior-x: contain;
991+
-webkit-overflow-scrolling: touch;
992+
scrollbar-width: none;
993+
-ms-overflow-style: none;
994+
}
995+
996+
.section-rail::-webkit-scrollbar {
997+
display: none;
987998
}
988999

9891000
.section-rail a {
@@ -999,6 +1010,7 @@ nav a.active {
9991010
text-decoration: none;
10001011
font-size: 0.72rem;
10011012
letter-spacing: 0.03em;
1013+
scroll-snap-align: center;
10021014
transition: transform 200ms ease, background 200ms ease, border-color 200ms ease, color 200ms ease;
10031015
}
10041016

0 commit comments

Comments
 (0)