Skip to content

Commit 8ab24b2

Browse files
JulienPalardmatrixise
authored andcommitted
[2.7] bpo-24712: Doc: Make sidebar sticky using browser support. (GH-13179)
Patch by Mike Taylor.
1 parent 7c2c01f commit 8ab24b2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Doc/tools/static/sidebar.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ $(function() {
4646
var dark_color = $('.related').css('background-color');
4747
var light_color = $('.document').css('background-color');
4848

49+
// set position: sticky on sidebar
50+
// (browsers that don't support this will fall-back to
51+
// positioning via scroll_sidebar)
52+
var supportsPositionSticky = (window.CSS && window.CSS.supports &&
53+
window.CSS.supports('position', 'sticky'));
54+
if (supportsPositionSticky) {
55+
sidebarwrapper.css('position', 'sticky');
56+
}
57+
4958
function get_viewport_height() {
5059
if (window.innerHeight)
5160
return window.innerHeight;
@@ -157,6 +166,9 @@ $(function() {
157166

158167
/* intelligent scrolling */
159168
function scroll_sidebar() {
169+
if (supportsPositionSticky) {
170+
return;
171+
}
160172
var sidebar_height = sidebarwrapper.height();
161173
var viewport_height = get_viewport_height();
162174
var offset = sidebar.position()['top'];

0 commit comments

Comments
 (0)