File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed
apify-docs-theme/static/js Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change 3232// load();
3333// }
3434// }, 500);
35+
36+ let lastKnownScrollHash = '' ;
37+
38+ // handles automatic scrolling of the API reference sidebar (redoc)
39+ function scrollSidebarItemIntoView ( ) {
40+ const hash = window . location . hash . substring ( 1 ) ;
41+
42+ if ( hash !== lastKnownScrollHash ) {
43+ const $li = document . querySelector ( `li[data-item-id="${ hash } "]` ) ;
44+
45+ if ( ! $li ) {
46+ return ;
47+ }
48+
49+ // not visible, click on the parent <li> first
50+ if ( ! $li . offsetParent ) {
51+ $li . parentElement ?. parentElement ?. click ( ) ;
52+ }
53+
54+ $li . scrollIntoView ( {
55+ // smooth would be nice, but it's not working in some case
56+ // behavior: 'smooth',
57+ block : 'nearest' ,
58+ inline : 'center' ,
59+ } ) ;
60+ lastKnownScrollHash = hash ;
61+ }
62+ }
63+
64+ let ticking = false ;
65+
66+ document . addEventListener ( 'scroll' , ( ) => {
67+ if ( ! ticking ) {
68+ // throttling based on current frame rate
69+ window . requestAnimationFrame ( ( ) => {
70+ scrollSidebarItemIntoView ( ) ;
71+ ticking = false ;
72+ } ) ;
73+
74+ ticking = true ;
75+ }
76+ } ) ;
You can’t perform that action at this time.
0 commit comments