Skip to content

Commit 440b1cf

Browse files
authored
Enhance Scroll Interaction with Threshold-Based Visibility for Navigation Elements (#1841)
1 parent aa1866c commit 440b1cf

8 files changed

+85
-36
lines changed

Diff for: assets/css/layout.css

+22-1
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,18 @@ body.sidebar-closed .sidebar-button {
123123
}
124124

125125
@media screen and (max-width: 768px) {
126+
.sidebar-button {
127+
top: 0;
128+
transition: top .3s;
129+
position: absolute;
130+
}
131+
132+
.sidebar-button.fixed {
133+
top: 0;
134+
transition: top .3s;
135+
position: fixed;
136+
}
137+
126138
.content,
127139
body.sidebar-opening .content {
128140
left: 0;
@@ -137,8 +149,17 @@ body.sidebar-closed .sidebar-button {
137149
}
138150

139151
body.sidebar-closed .sidebar-button {
152+
position: fixed;
153+
left: 0;
154+
top: 0;
155+
transition: top .3s;
156+
position: absolute;
157+
}
158+
159+
body.sidebar-closed .sidebar-button.fixed {
140160
position: fixed;
141161
left: 0;
142-
transition: top 0.9s;
162+
top: 0;
163+
transition: top .3s;
143164
}
144165
}

Diff for: assets/css/search-bar.css

+24-15
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,3 @@
1-
.background-layer {
2-
display: none;
3-
position: fixed;
4-
top: 0;
5-
left: 0;
6-
right: 0;
7-
height: 70px;
8-
background-color: var(--background);
9-
}
10-
111
.top-search {
122
margin-top: 10px;
133
}
@@ -130,13 +120,17 @@
130120
}
131121

132122
@media (max-width: 768px) {
133-
.background-layer {
134-
display: block;
135-
z-index: 10;
136-
transition: top 0.3s;
123+
124+
.top-search {
125+
margin-top: 0;
126+
position: absolute;
127+
top: 13px;
128+
left: 56px;
129+
right: 20px;
130+
z-index: 99;
137131
}
138132

139-
.top-search {
133+
.top-search.fixed {
140134
margin-top: 0;
141135
position: fixed;
142136
top: 13px;
@@ -146,6 +140,21 @@
146140
z-index: 99;
147141
}
148142

143+
.background-layer {
144+
display: block;
145+
z-index: 10;
146+
transition: top 0.3s;
147+
}
148+
149+
.background-layer.fixed {
150+
position: fixed;
151+
top: 0;
152+
left: 0;
153+
right: 0;
154+
height: 70px;
155+
background-color: var(--background);
156+
}
157+
149158
.search-settings {
150159
width: 100%;
151160
box-sizing: border-box;

Diff for: assets/js/search-bar.js

+25-6
Original file line numberDiff line numberDiff line change
@@ -142,27 +142,46 @@ function isMacOS () {
142142
return /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform)
143143
}
144144

145+
window.addEventListener('scroll', function () {
146+
const topSearch = document.querySelector('.top-search')
147+
const sidebarMenu = document.getElementById('sidebar-menu')
148+
const backgroundLayer = document.querySelector('.background-layer')
149+
const currentScroll = window.scrollY
150+
151+
// Add 'fixed' class when not at the top
152+
if (currentScroll > 70) {
153+
topSearch.classList.add('fixed')
154+
sidebarMenu.classList.add('fixed')
155+
backgroundLayer.classList.add('fixed')
156+
} else {
157+
// Remove 'fixed' class when at the top
158+
topSearch.classList.remove('fixed')
159+
sidebarMenu.classList.remove('fixed')
160+
backgroundLayer.classList.remove('fixed')
161+
}
162+
})
163+
145164
let lastScrollTop = window.scrollY
146165
const topSearch = document.querySelector('.top-search')
147166
const sidebarMenu = document.getElementById('sidebar-menu')
148167
const backgroundLayer = document.querySelector('.background-layer')
168+
const scrollThreshold = 56 // Set a threshold for scroll, adjust as needed
149169

150170
window.addEventListener('scroll', function () {
151171
const currentScroll = window.scrollY
152172

153-
if (currentScroll > lastScrollTop) {
154-
// Scrolling down
173+
if (currentScroll > lastScrollTop && currentScroll > scrollThreshold) {
174+
// Scrolling down and past the threshold
155175
topSearch.style.top = '-50px'
156176
backgroundLayer.style.top = '-70px'
157-
// Only hide sidebarMenu if aria-expanded is not true
158177
if (sidebarMenu.getAttribute('aria-expanded') !== 'true') {
159-
sidebarMenu.style.display = 'none'
178+
sidebarMenu.style.top = '-50px'
160179
}
161180
} else {
162-
// Scrolling up
181+
// Scrolling up or at the top of the page
163182
topSearch.style.top = '11px'
164183
backgroundLayer.style.top = '0px'
165-
sidebarMenu.style.display = 'block'
184+
sidebarMenu.style.top = '0px'
166185
}
167186

168187
lastScrollTop = currentScroll <= 0 ? 0 : currentScroll

Diff for: formatters/html/dist/html-I2V5AYFT.js renamed to formatters/html/dist/html-VPLTBHQU.js

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: formatters/html/dist/html-elixir-KPL2KMOQ.css

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: formatters/html/dist/html-elixir-OX6HFLA4.css

-6
This file was deleted.

Diff for: formatters/html/dist/html-erlang-D7OKCZI3.css

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: formatters/html/dist/html-erlang-XUY32CF7.css

-6
This file was deleted.

0 commit comments

Comments
 (0)