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