Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit245418d

Browse files
committed
Sidebar: "dumb" scrolling
Just make the sidebar stick to the top with CSS and show a scrollbar onoverflow. There's no fallback for older browsers -- since up to now,this didn't work for anyone (because "intelligent" scrolling has beenbroken for years), I assume improving the UX at least for modernbrowsers is still a net improvement.
1 parenta7b271a commit245418d

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 slightlymodified 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
varjwindow=$(window);
29-
varjdocument=$(document);
3029
varbodywrapper=$('.bodywrapper');
3130
vardocumentwrapper=$('.documentwrapper');
3231
varsidebar=$('.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
functioncollapse_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
varsidebarbutton=$('#sidebarbutton');
163160
set_position_from_cookie();
164-
165-
166-
/* intelligent scrolling */
167-
functionscroll_sidebar(){
168-
varsidebar_height=sidebarwrapper.height();
169-
varviewport_height=get_viewport_height();
170-
varoffset=sidebar.position()['top'];
171-
varwintop=jwindow.scrollTop();
172-
varwinbot=wintop+viewport_height;
173-
varcurtop=sidebarwrapper.position()['top'];
174-
varcurbot=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-
elseif(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)

[8]ページ先頭

©2009-2025 Movatter.jp