mirror of
https://github.com/readthedocs/sphinx_rtd_theme.git
synced 2025-02-25 18:55:21 -06:00
Make the nav sidebar's scroll-to-current-page behaviour less jumpy
This avoids scrolling the sidebar when the link is already in view by using "nearest" for the vertical axis ("block") instead of the default of "start". This behaviour is much better when clicking on items in the current viewport, especially if the current viewport matches the initial viewport. It's still a little jumpy when the current link isn't visible in the initial viewport, because the sidebar position still changes across page loads. But the new behaviour solves the big problem on initial home page loads with a long sidebar where the logo and project title would be immediately scrolled out of view. Related to #824.
This commit is contained in:
parent
0da22b885b
commit
b8535aee8f
File diff suppressed because one or more lines are too long
10
src/theme.js
10
src/theme.js
@ -159,7 +159,15 @@ function ThemeNav () {
|
||||
.addClass('current')
|
||||
.attr('aria-expanded','true');
|
||||
}
|
||||
link[0].scrollIntoView();
|
||||
/* Scroll the link's top-level parent into view first. Then
|
||||
* scroll the link itself into view, which will only have an
|
||||
* effect if the top-level parent is taller than the viewport
|
||||
* and the link is still outside the viewport after the first
|
||||
* scroll. (This seems likely to be rare.)
|
||||
*/
|
||||
link.closest('li.toctree-l1')[0]
|
||||
.scrollIntoView({block: "nearest"});
|
||||
link[0].scrollIntoView({block: "nearest"});
|
||||
}
|
||||
}
|
||||
catch (err) {
|
||||
|
Loading…
Reference in New Issue
Block a user