Skip to content

Commit 87efbfa

Browse files
authored
Visibility of Navigation Elements on Page Load and Scroll (#1838)
1 parent 5ddc3f5 commit 87efbfa

File tree

10 files changed

+115
-34
lines changed

10 files changed

+115
-34
lines changed

assets/css/autocomplete.css

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
.autocomplete {
22
display: none;
3-
height: 0;
4-
margin-right: 32px;
5-
overflow: visible;
6-
position: relative;
3+
position: absolute;
4+
width: 84%;
5+
top: 55px;
76
}
87

98
.autocomplete .triangle {
@@ -36,7 +35,7 @@
3635
.autocomplete-results .show {
3736
white-space: normal;
3837
overflow-x: hidden;
39-
width: 62%;
38+
width: 84%;
4039
}
4140

4241
.autocomplete-results .bold {
@@ -135,18 +134,41 @@
135134
}
136135

137136
@media (max-width: 480px) {
137+
138+
.autocomplete {
139+
width: 90%;
140+
}
141+
138142
.autocomplete .triangle {
139143
left: 27%;
140144
}
141145
}
142146

147+
@media (min-width: 481px) and (max-width: 767px) {
148+
149+
.autocomplete {
150+
width: 95%;
151+
}
152+
153+
.autocomplete .triangle {
154+
left: 17%;
155+
}
156+
}
157+
143158
@media (max-width: 767px) {
159+
.autocomplete {
160+
top: 50px;
161+
left: 0;
162+
right: 0;
163+
z-index: 200;
164+
}
165+
144166
.autocomplete .triangle {
145167
left: 17%;
146168
}
147169
}
148170

149-
@media (max-width: 1024px) {
171+
@media (max-width: 1023px) {
150172
.autocomplete-results {
151173
gap: 0;
152174
}

assets/css/layout.css

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ body {
3535
position: fixed;
3636
top: 0;
3737
left: 0;
38-
z-index: 4;
38+
z-index: 100;
3939
}
4040

4141
.sidebar-button {
4242
--sidebarButtonRightOpen: 4px;
4343
position: fixed;
44-
z-index: 99;
44+
z-index: 200;
4545
left: 0;
4646
transition: all var(--sidebarTransitionDuration) ease-in-out;
4747
will-change: transform;
@@ -53,7 +53,6 @@ body {
5353
left: var(--sidebarWidth);
5454
height: 100%;
5555
position: absolute;
56-
z-index: 3;
5756
}
5857

5958
.content-inner {
@@ -124,19 +123,22 @@ body.sidebar-closed .sidebar-button {
124123
}
125124

126125
@media screen and (max-width: 768px) {
127-
.content,
126+
.content,
128127
body.sidebar-opening .content {
129128
left: 0;
130129
width: 100%;
131130
}
132131

133132
.content-inner {
134-
padding-top: 13px;
133+
padding-top: 43px;
135134
padding-bottom: 26px;
136135
overflow-x: auto;
136+
137137
}
138138

139139
body.sidebar-closed .sidebar-button {
140-
position: absolute;
140+
position: fixed;
141+
left: 0;
142+
transition: top 0.9s;
141143
}
142-
}
144+
}

assets/css/search-bar.css

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
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 {
212
margin-top: 10px;
313
}
@@ -6,14 +16,15 @@
616
display: flex;
717
column-gap: 12px;
818
align-items: center;
19+
width: 100%;
920
}
1021

1122
.search-bar {
1223
border: 1px solid var(--searchBarBorder);
1324
border-radius: 8px;
1425
height: 48px;
1526
position: relative;
16-
flex-grow: 1;
27+
width: 100%;
1728
}
1829

1930
.top-search .search-bar .search-input {
@@ -56,7 +67,7 @@
5667
position: absolute;
5768
top: 60%;
5869
transform: translateY(-60%);
59-
z-index: 2;
70+
z-index: 99;
6071
}
6172

6273
.top-search .search-bar.selected .search-button,
@@ -80,7 +91,7 @@
8091
transform: scaleY(0);
8192
top: calc(50% - 11px);
8293
transition: 0.15s transform ease-out;
83-
z-index: 2;
94+
z-index: 99;
8495
}
8596

8697
.top-search .search-bar .search-close-button:hover {
@@ -114,13 +125,30 @@
114125

115126
@media (max-width: 480px) or ((min-width: 481px) and (max-width: 768px)) {
116127
.search-bar {
117-
margin-left: 35px;
128+
margin-left: 0px;
118129
}
119130
}
120131

121132
@media (max-width: 768px) {
133+
.background-layer {
134+
display: block;
135+
z-index: 10;
136+
transition: top 0.3s;
137+
}
138+
122139
.top-search {
123140
margin-top: 0;
141+
position: fixed;
142+
top: 13px;
143+
left: 56px;
144+
right: 20px;
145+
transition: top 0.3s;
146+
z-index: 99;
147+
}
148+
149+
.search-settings {
150+
width: 100%;
151+
box-sizing: border-box;
124152
}
125153
}
126154

assets/js/search-bar.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,3 +141,29 @@ function hideAutocomplete () {
141141
function isMacOS () {
142142
return /(Mac|iPhone|iPod|iPad)/i.test(navigator.platform)
143143
}
144+
145+
let lastScrollTop = window.scrollY
146+
const topSearch = document.querySelector('.top-search')
147+
const sidebarMenu = document.getElementById('sidebar-menu')
148+
const backgroundLayer = document.querySelector('.background-layer')
149+
150+
window.addEventListener('scroll', function () {
151+
const currentScroll = window.scrollY
152+
153+
if (currentScroll > lastScrollTop) {
154+
// Scrolling down
155+
topSearch.style.top = '-50px'
156+
backgroundLayer.style.top = '-70px'
157+
// Only hide sidebarMenu if aria-expanded is not true
158+
if (sidebarMenu.getAttribute('aria-expanded') !== 'true') {
159+
sidebarMenu.style.display = 'none'
160+
}
161+
} else {
162+
// Scrolling up
163+
topSearch.style.top = '11px'
164+
backgroundLayer.style.top = '0px'
165+
sidebarMenu.style.display = 'block'
166+
}
167+
168+
lastScrollTop = currentScroll <= 0 ? 0 : currentScroll
169+
}, false)

formatters/html/dist/html-CILPWI2Q.js renamed to formatters/html/dist/html-I2V5AYFT.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

formatters/html/dist/html-elixir-OX6HFLA4.css

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

formatters/html/dist/html-elixir-YFWKN3MH.css

Lines changed: 0 additions & 6 deletions
This file was deleted.

formatters/html/dist/html-erlang-XUY32CF7.css

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

formatters/html/dist/html-erlang-Y7RP5ZQB.css

Lines changed: 0 additions & 6 deletions
This file was deleted.

lib/ex_doc/formatter/html/templates/sidebar_template.eex

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
<div class="main">
22

3-
<button class="sidebar-button sidebar-toggle" aria-label="toggle sidebar" aria-controls="sidebar">
3+
<button id="sidebar-menu" class="sidebar-button sidebar-toggle" aria-label="toggle sidebar" aria-controls="sidebar">
44
<i class="ri-menu-line ri-lg" title="Collapse/expand sidebar"></i>
55
</button>
66

7+
<div class="background-layer"></div>
8+
79
<nav id="sidebar" class="sidebar">
810
<% url = config.homepage_url || "#{config.main}.html" %>
911
<div class="sidebar-header">
@@ -82,11 +84,12 @@
8284
<i class="ri-close-line ri-lg" title="Cancel search"></i>
8385
</button>
8486
</form>
87+
<div class="autocomplete">
88+
</div>
8589
<button class="icon-settings display-settings">
8690
<i class="ri-settings-3-line"></i>
8791
<span class="sr-only">Settings</span>
8892
</button>
8993
</div>
90-
</div>
91-
<div class="autocomplete">
94+
9295
</div>

0 commit comments

Comments
 (0)