Skip to content

Commit a3ab309

Browse files
committed
Make the search bar fixed, hide the logo when scrolling down
This closes #2778.
1 parent 9329aa8 commit a3ab309

File tree

3 files changed

+69
-0
lines changed

3 files changed

+69
-0
lines changed

_static/css/custom.css

+28
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,26 @@ code,
422422
background-color: var(--navbar-background-color);
423423
}
424424

425+
@media only screen and (min-width: 768px) {
426+
.wy-side-nav-search {
427+
/* Keep the search field visible when scrolling down */
428+
position: fixed;
429+
}
430+
431+
/* Simulate a drop shadow that only affects the bottom edge */
432+
/* This is used to indicate the search bar is fixed */
433+
.wy-side-nav-search::after {
434+
content: '';
435+
position: absolute;
436+
left: 0;
437+
bottom: -8px;
438+
width: 300px;
439+
height: 8px;
440+
pointer-events: none;
441+
background: linear-gradient(hsla(0, 0%, 0%, 0.2), transparent);
442+
}
443+
}
444+
425445
.wy-side-nav-search > a:hover,
426446
.wy-side-nav-search .wy-dropdown > a:hover {
427447
background-color: var(--navbar-background-color-hover);
@@ -494,6 +514,14 @@ code,
494514
width: 308px;
495515
}
496516

517+
@media only screen and (min-width: 768px) {
518+
.wy-menu-vertical {
519+
/* Account for the fixed logo and search form */
520+
/* (prevents the navbar from being hidden behind it) */
521+
margin-top: 330px;
522+
}
523+
}
524+
497525
.wy-menu-vertical a {
498526
color: var(--navbar-level-1-color);
499527
}

_static/js/custom.js

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// The number of pixels the user must scroll by before the logo is hidden.
2+
const scrollTopPixels = 40;
3+
4+
// Hide the navigation bar logo when scrolling down on desktop platforms.
5+
// The logo is quite tall, so this helps make the rest of the navigation bar
6+
// more readable.
7+
function registerOnScrollEvent(mediaQuery) {
8+
// The navigation bar that contains the logo.
9+
const $navbar = $('.wy-side-scroll');
10+
11+
// The anchor that contains the logo. This element will be hidden
12+
// (instead of hiding just the logo), otherwise, a small clickable area
13+
// would remain visible.
14+
const $logo = $('.wy-side-nav-search > a');
15+
16+
if (mediaQuery.matches) {
17+
// We're on desktop; register the scroll event.
18+
$navbar.scroll(function() {
19+
if ($(this).scrollTop() >= scrollTopPixels) {
20+
$logo.hide();
21+
} else {
22+
$logo.show();
23+
}
24+
});
25+
} else {
26+
// We're on mobile; unregister the scroll event so the logo isn't hidden
27+
// when scrolling.
28+
$logo.show();
29+
$navbar.unbind('scroll');
30+
}
31+
}
32+
33+
$(document).ready(() => {
34+
const mediaQuery = window.matchMedia('only screen and (min-width: 768px)');
35+
registerOnScrollEvent(mediaQuery);
36+
mediaQuery.addListener(registerOnScrollEvent);
37+
});

conf.py

+4
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@
9999
'css/custom.css',
100100
]
101101

102+
html_js_files = [
103+
'js/custom.js',
104+
]
105+
102106
# Output file base name for HTML help builder
103107
htmlhelp_basename = 'GodotEnginedoc'
104108

0 commit comments

Comments
 (0)