From c6f7a1771e624eef053fa9526a44021498fe10f7 Mon Sep 17 00:00:00 2001 From: Will Stevens Date: Wed, 11 Jun 2014 12:30:56 -0400 Subject: [PATCH] made sticky nav actually stick even on long menus --- sphinx_rtd_theme/static/js/theme.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/sphinx_rtd_theme/static/js/theme.js b/sphinx_rtd_theme/static/js/theme.js index 60520cc3..25f53484 100644 --- a/sphinx_rtd_theme/static/js/theme.js +++ b/sphinx_rtd_theme/static/js/theme.js @@ -21,16 +21,19 @@ window.SphinxRtdTheme = (function (jquery) { var navBar, win, stickyNavCssClass = 'stickynav', - applyStickNav = function () { - if (navBar.height() <= win.height()) { - navBar.addClass(stickyNavCssClass); - } else { - navBar.removeClass(stickyNavCssClass); - } - }, + winScroll = false, enable = function () { - applyStickNav(); - win.on('resize', applyStickNav); + navBar.addClass(stickyNavCssClass); + win.on('scroll', function() { // set flag on scroll event + winScroll = true; + }); + // use setInterval to only handle a subset of scroll events so we don't kill scroll performance + setInterval(function() { + if (winScroll) { + winScroll = false; + navBar.scrollTop(win.scrollTop()); + } + }, 100); }, init = function () { navBar = jquery('nav.wy-nav-side:first');