Skip to content

Commit 245418d

Browse files
committed
Sidebar: "dumb" scrolling
Just make the sidebar stick to the top with CSS and show a scrollbar on overflow. There's no fallback for older browsers -- since up to now, this didn't work for anyone (because "intelligent" scrolling has been broken for years), I assume improving the UX at least for modern browsers is still a net improvement.
1 parent a7b271a commit 245418d

File tree

2 files changed

+13
-36
lines changed

2 files changed

+13
-36
lines changed

python_docs_theme/static/pydoctheme.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ form.inline-search input[type="submit"] {
5252
}
5353

5454
div.sphinxsidebar {
55+
position: sticky;
56+
top: 0;
57+
height: 100vh;
5558
background-color: #eeeeee;
5659
border-radius: 5px;
5760
line-height: 130%;
@@ -62,6 +65,13 @@ div.sphinxsidebar h3, div.sphinxsidebar h4 {
6265
margin-top: 1.5em;
6366
}
6467

68+
div.sphinxsidebarwrapper {
69+
box-sizing: border-box;
70+
height: 100%;
71+
overflow-x: hidden;
72+
overflow-y: auto;
73+
}
74+
6575
div.sphinxsidebarwrapper > h3:first-child {
6676
margin-top: 0.2em;
6777
}

python_docs_theme/static/sidebar.js

Lines changed: 3 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
* sidebar.js
33
* ~~~~~~~~~~
44
*
5-
* This script makes the Sphinx sidebar collapsible and implements intelligent
6-
* scrolling. This is a slightly modified version of Sphinx's own sidebar.js.
5+
* This script makes the Sphinx sidebar collapsible. This is a slightly
6+
* modified version of Sphinx's own sidebar.js.
77
*
88
* .sphinxsidebar contains .sphinxsidebarwrapper. This script adds in
99
* .sphixsidebar, after .sphinxsidebarwrapper, the #sidebarbutton used to
@@ -26,7 +26,6 @@ $(function() {
2626
// the 'sidebarbutton' element is defined as global after its
2727
// creation, in the add_sidebar_button function
2828
var jwindow = $(window);
29-
var jdocument = $(document);
3029
var bodywrapper = $('.bodywrapper');
3130
var documentwrapper = $('.documentwrapper');
3231
var sidebar = $('.sphinxsidebar');
@@ -62,8 +61,6 @@ $(function() {
6261
expand_sidebar();
6362
else
6463
collapse_sidebar();
65-
// adjust the scrolling of the sidebar
66-
scroll_sidebar();
6764
}
6865

6966
function collapse_sidebar() {
@@ -100,7 +97,7 @@ $(function() {
10097
sidebarwrapper.css({
10198
'float': 'left',
10299
'margin-right': '0',
103-
'width': ssb_width_expanded - 28
100+
'width': ssb_width_expanded - 13
104101
});
105102
// create the button
106103
sidebar.append(
@@ -161,34 +158,4 @@ $(function() {
161158
add_sidebar_button();
162159
var sidebarbutton = $('#sidebarbutton');
163160
set_position_from_cookie();
164-
165-
166-
/* intelligent scrolling */
167-
function scroll_sidebar() {
168-
var sidebar_height = sidebarwrapper.height();
169-
var viewport_height = get_viewport_height();
170-
var offset = sidebar.position()['top'];
171-
var wintop = jwindow.scrollTop();
172-
var winbot = wintop + viewport_height;
173-
var curtop = sidebarwrapper.position()['top'];
174-
var curbot = curtop + sidebar_height;
175-
// does sidebar fit in window?
176-
if (sidebar_height < viewport_height) {
177-
// yes: easy case -- always keep at the top
178-
sidebarwrapper.css('top', $u.min([$u.max([0, wintop - offset - 10]),
179-
jdocument.height() - sidebar_height - 200]));
180-
}
181-
else {
182-
// no: only scroll if top/bottom edge of sidebar is at
183-
// top/bottom edge of window
184-
if (curtop > wintop && curbot > winbot) {
185-
sidebarwrapper.css('top', $u.max([wintop - offset - 10, 0]));
186-
}
187-
else if (curtop < wintop && curbot < winbot) {
188-
sidebarwrapper.css('top', $u.min([winbot - sidebar_height - offset - 20,
189-
jdocument.height() - sidebar_height - 200]));
190-
}
191-
}
192-
}
193-
jwindow.scroll(scroll_sidebar);
194161
});

0 commit comments

Comments
 (0)