Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Header: Hide on scroll #1125

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sphinx_rtd_theme/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

{#- MOBILE NAV, TRIGGLES SIDE NAV ON TOGGLE #}
<nav class="wy-nav-top" aria-label="{{ _('Top') }}" {% if theme_style_nav_header_background %} style="background: {{theme_style_nav_header_background}}" {% endif %}>
<nav class="wy-nav-top" aria-label="{{ _('Top') }}" id="navbar" {% if theme_style_nav_header_background %} style="background: {{theme_style_nav_header_background}}" {% endif %}>
{%- block mobile_nav %}
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="{{ pathto(master_doc) }}">{{ project }}</a>
Expand Down
2 changes: 1 addition & 1 deletion sphinx_rtd_theme/static/css/theme.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion sphinx_rtd_theme/static/js/theme.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 10 additions & 11 deletions src/sass/_theme_layout.sass
Original file line number Diff line number Diff line change
Expand Up @@ -293,30 +293,28 @@ html

.wy-nav-top
display: none
background: $link-color
background: $nav-search-background-color
color: $white
padding: ($gutter / 4) ($gutter / 2)
position: relative
line-height: 50px
position: fixed
top: 0
width: 100%
height: $nav-header-height
line-height: $nav-header-height
text-align: center
font-size: 100%
transition: top 0.4s
+clearfix
a
color: $white
font-weight: bold
+font-smooth
img
margin-right: $base-line-height / 2
height: 45px
width: 45px
background-color: $menu-logo-color
padding: 5px
border-radius: 100%
i
font-size: 30px
float: left
cursor: pointer
padding-top: inherit
padding-left: $gutter / 4
line-height: $nav-header-height

.wy-nav-content-wrap
margin-left: $nav-desktop-width
Expand Down Expand Up @@ -400,6 +398,7 @@ footer
.wy-nav-content-wrap
margin-left: 0
.wy-nav-content
margin-top: $nav-header-height
padding: $gutter
&.shift
position: fixed
Expand Down
1 change: 1 addition & 0 deletions src/sass/_theme_variables.sass
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
$fa-font-path: "~font-awesome/fonts"
$static-img: "../img/"

$nav-header-height: 50px
$nav-content-width: 800px
$nav-media-query: $nav-desktop-width + $nav-content-width

Expand Down
18 changes: 18 additions & 0 deletions src/theme.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@ var jQuery = (typeof(window) != 'undefined') ? window.jQuery : require('jquery')

// Sphinx theme nav state
function ThemeNav () {
var delta = 5;

/* When the user scrolls down, hide the navbar. When the user scrolls up, show the navbar */
var prevScrollpos = window.pageYOffset;
window.onscroll = function() {
var currentScrollPos = window.pageYOffset;


if(Math.abs(prevScrollpos - currentScrollPos) <= delta)
return

if ((prevScrollpos > currentScrollPos) || (currentScrollPos < 25)) {
document.getElementById("navbar").style.top = "0";
} else {
document.getElementById("navbar").style.top = "-50px";
}
prevScrollpos = currentScrollPos;
}

var nav = {
navBar: null,
Expand Down