2
0
Эх сурвалжийг харах

Merge pull request #3099 from Calinou/make-search-bar-fixed

Make the search bar fixed, hide the logo when scrolling down
Rémi Verschelde 5 жил өмнө
parent
commit
7275e7da10
3 өөрчлөгдсөн 69 нэмэгдсэн , 0 устгасан
  1. 28 0
      _static/css/custom.css
  2. 37 0
      _static/js/custom.js
  3. 4 0
      conf.py

+ 28 - 0
_static/css/custom.css

@@ -422,6 +422,26 @@ code,
     background-color: var(--navbar-background-color);
 }
 
+@media only screen and (min-width: 768px) {
+    .wy-side-nav-search {
+        /* Keep the search field visible when scrolling down */
+        position: fixed;
+    }
+
+    /* Simulate a drop shadow that only affects the bottom edge */
+    /* This is used to indicate the search bar is fixed */
+    .wy-side-nav-search::after {
+        content: '';
+        position: absolute;
+        left: 0;
+        bottom: -8px;
+        width: 300px;
+        height: 8px;
+        pointer-events: none;
+        background: linear-gradient(hsla(0, 0%, 0%, 0.2), transparent);
+    }
+}
+
 .wy-side-nav-search > a:hover,
 .wy-side-nav-search .wy-dropdown > a:hover {
     background-color: var(--navbar-background-color-hover);
@@ -494,6 +514,14 @@ code,
     width: 308px;
 }
 
+@media only screen and (min-width: 768px) {
+    .wy-menu-vertical {
+        /* Account for the fixed logo and search form */
+        /* (prevents the navbar from being hidden behind it) */
+        margin-top: 330px;
+    }
+}
+
 .wy-menu-vertical a {
     color: var(--navbar-level-1-color);
 }

+ 37 - 0
_static/js/custom.js

@@ -0,0 +1,37 @@
+// The number of pixels the user must scroll by before the logo is hidden.
+const scrollTopPixels = 40;
+
+// Hide the navigation bar logo when scrolling down on desktop platforms.
+// The logo is quite tall, so this helps make the rest of the navigation bar
+// more readable.
+function registerOnScrollEvent(mediaQuery) {
+  // The navigation bar that contains the logo.
+  const $navbar = $('.wy-side-scroll');
+
+  // The anchor that contains the logo. This element will be hidden
+  // (instead of hiding just the logo), otherwise, a small clickable area
+  // would remain visible.
+  const $logo = $('.wy-side-nav-search > a');
+
+  if (mediaQuery.matches) {
+    // We're on desktop; register the scroll event.
+    $navbar.scroll(function() {
+      if ($(this).scrollTop() >= scrollTopPixels) {
+        $logo.hide();
+      } else {
+        $logo.show();
+      }
+    });
+  } else {
+    // We're on mobile; unregister the scroll event so the logo isn't hidden
+    // when scrolling.
+    $logo.show();
+    $navbar.unbind('scroll');
+  }
+}
+
+$(document).ready(() => {
+  const mediaQuery = window.matchMedia('only screen and (min-width: 768px)');
+  registerOnScrollEvent(mediaQuery);
+  mediaQuery.addListener(registerOnScrollEvent);
+});

+ 4 - 0
conf.py

@@ -99,6 +99,10 @@ html_css_files = [
     'css/custom.css',
 ]
 
+html_js_files = [
+    'js/custom.js',
+]
+
 # Output file base name for HTML help builder
 htmlhelp_basename = 'GodotEnginedoc'