Skip to content

Commit 3a00225

Browse files
committed
Refactor scrolling
1 parent 440b1cf commit 3a00225

8 files changed

+51
-84
lines changed

Diff for: assets/css/layout.css

+9-24
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ body {
4242
--sidebarButtonRightOpen: 4px;
4343
position: fixed;
4444
z-index: 200;
45+
top: 0;
4546
left: 0;
4647
transition: all var(--sidebarTransitionDuration) ease-in-out;
4748
will-change: transform;
@@ -123,19 +124,7 @@ body.sidebar-closed .sidebar-button {
123124
}
124125

125126
@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-
138-
.content,
127+
.content,
139128
body.sidebar-opening .content {
140129
left: 0;
141130
width: 100%;
@@ -145,21 +134,17 @@ body.sidebar-closed .sidebar-button {
145134
padding-top: 43px;
146135
padding-bottom: 26px;
147136
overflow-x: auto;
148-
149137
}
150138

151139
body.sidebar-closed .sidebar-button {
152-
position: fixed;
153-
left: 0;
154-
top: 0;
155-
transition: top .3s;
156140
position: absolute;
157141
}
158142

159-
body.sidebar-closed .sidebar-button.fixed {
160-
position: fixed;
161-
left: 0;
162-
top: 0;
163-
transition: top .3s;
143+
.sm-fixed {
144+
position: fixed !important;
164145
}
165-
}
146+
147+
.sm-hidden {
148+
top: -70px !important;
149+
}
150+
}

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

+7-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.top-search {
22
margin-top: 10px;
3+
height: 70px;
4+
background-color: var(--background);
35
}
46

57
.search-settings {
@@ -120,41 +122,28 @@
120122
}
121123

122124
@media (max-width: 768px) {
123-
124125
.top-search {
125126
margin-top: 0;
126127
position: absolute;
127128
top: 13px;
128-
left: 56px;
129-
right: 20px;
130-
z-index: 99;
131-
}
132-
133-
.top-search.fixed {
134-
margin-top: 0;
135-
position: fixed;
136-
top: 13px;
129+
height: 57px;
137130
left: 56px;
138131
right: 20px;
139132
transition: top 0.3s;
140133
z-index: 99;
141134
}
142135

143136
.background-layer {
144-
display: block;
145-
z-index: 10;
146-
transition: top 0.3s;
147-
}
148-
149-
.background-layer.fixed {
150-
position: fixed;
137+
position: absolute;
151138
top: 0;
152139
left: 0;
153140
right: 0;
154141
height: 70px;
155142
background-color: var(--background);
143+
transition: top 0.3s;
144+
z-index: 98;
156145
}
157-
146+
158147
.search-settings {
159148
width: 100%;
160149
box-sizing: border-box;

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

+21-28
Original file line numberDiff line numberDiff line change
@@ -142,46 +142,39 @@ 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-
164145
let lastScrollTop = window.scrollY
165146
const topSearch = document.querySelector('.top-search')
166147
const sidebarMenu = document.getElementById('sidebar-menu')
167148
const backgroundLayer = document.querySelector('.background-layer')
168-
const scrollThreshold = 56 // Set a threshold for scroll, adjust as needed
149+
const scrollThreshold = 70 // Set a threshold for scroll, adjust as needed
169150

170151
window.addEventListener('scroll', function () {
171152
const currentScroll = window.scrollY
172153

154+
// Add 'fixed' class when not at the top
155+
if (currentScroll > scrollThreshold * 2) {
156+
topSearch.classList.add('sm-fixed')
157+
sidebarMenu.classList.add('sm-fixed')
158+
backgroundLayer.classList.add('sm-fixed')
159+
}
160+
161+
if (currentScroll == 0) {
162+
// Remove 'fixed' class when at the top
163+
topSearch.classList.remove('sm-fixed')
164+
sidebarMenu.classList.remove('sm-fixed')
165+
backgroundLayer.classList.remove('sm-fixed')
166+
}
167+
173168
if (currentScroll > lastScrollTop && currentScroll > scrollThreshold) {
174169
// Scrolling down and past the threshold
175-
topSearch.style.top = '-50px'
176-
backgroundLayer.style.top = '-70px'
177-
if (sidebarMenu.getAttribute('aria-expanded') !== 'true') {
178-
sidebarMenu.style.top = '-50px'
179-
}
170+
topSearch.classList.add('sm-hidden')
171+
sidebarMenu.classList.add('sm-hidden')
172+
backgroundLayer.classList.add('sm-hidden')
180173
} else {
181174
// Scrolling up or at the top of the page
182-
topSearch.style.top = '11px'
183-
backgroundLayer.style.top = '0px'
184-
sidebarMenu.style.top = '0px'
175+
topSearch.classList.remove('sm-hidden')
176+
sidebarMenu.classList.remove('sm-hidden')
177+
backgroundLayer.classList.remove('sm-hidden')
185178
}
186179

187180
lastScrollTop = currentScroll <= 0 ? 0 : currentScroll

Diff for: formatters/html/dist/html-VPLTBHQU.js renamed to formatters/html/dist/html-CN5C4NZC.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
This file was deleted.

Diff for: formatters/html/dist/html-elixir-PVS4QQIM.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-D7OKCZI3.css

-6
This file was deleted.

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

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

0 commit comments

Comments
 (0)