File tree Expand file tree Collapse file tree 1 file changed +19
-2
lines changed
apify-docs-theme/static/js Expand file tree Collapse file tree 1 file changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -61,6 +61,20 @@ function scrollSidebarItemIntoView() {
6161 }
6262}
6363
64+ // handles automatic scrolling of the API reference sidebar (openapi-docs)
65+ function scrollOpenApiSidebarItemIntoView ( ) {
66+ const $li = document . querySelector ( `li > a.menu__link--active[href]` ) ;
67+
68+ if ( ! $li ) {
69+ return ;
70+ }
71+
72+ $li . scrollIntoView ( {
73+ block : 'nearest' ,
74+ inline : 'center' ,
75+ } ) ;
76+ }
77+
6478let ticking = false ;
6579
6680document . addEventListener ( 'scroll' , ( ) => {
@@ -75,7 +89,10 @@ document.addEventListener('scroll', () => {
7589 }
7690} ) ;
7791
78- document . addEventListener ( 'DOMContentLoaded ' , ( ) => {
92+ window . addEventListener ( 'load ' , ( ) => {
7993 // we need to wait a bit more, since the event fires too soon, and a lot of hydration is done after it
80- setTimeout ( ( ) => scrollSidebarItemIntoView ( ) , 3000 ) ;
94+ setTimeout ( ( ) => scrollSidebarItemIntoView ( ) , 1000 ) ;
95+
96+ // docusaurus-openapi-docs plugin: scroll sidebar into viewport, no need for a large timeout here
97+ setTimeout ( ( ) => scrollOpenApiSidebarItemIntoView ( ) , 100 ) ;
8198} ) ;
You can’t perform that action at this time.
0 commit comments