77 < link rel ="shortcut icon " href ="/files/favicon_white.ico " media ="(prefers-color-scheme: dark) "/>
88 < link rel ="shortcut icon " href ="/files/favicon.ico " media ="(prefers-color-scheme: light) " />
99 < link rel ="stylesheet " type ="text/css " href ="/files/main.css ">
10- < link type ="text/css " rel ="stylesheet " href ="styles/page.css ">
1110 <!-- console sandbox -->
1211 < script type ="module ">
1312 import * as THREE from '../build/three.module.js' ;
@@ -246,7 +245,7 @@ <h1><a href="https://threejs.org">three.js</a></h1>
246245 if ( fullPageName === selectedPage || pageName === selectedPage ) {
247246
248247 link . classList . add ( 'selected' ) ;
249- link . scrollIntoView ( { block : 'center' } ) ;
248+ scrollIntoViewVertical ( link ) ;
250249
251250 }
252251
@@ -256,6 +255,19 @@ <h1><a href="https://threejs.org">three.js</a></h1>
256255
257256 }
258257
258+ function scrollIntoViewVertical ( element ) {
259+
260+ const container = document . getElementById ( 'content' ) ;
261+ const elementTop = element . offsetTop ;
262+ const elementHeight = element . offsetHeight ;
263+ const viewportHeight = window . innerHeight ;
264+
265+ // Scroll to center the element vertically using viewport height
266+ const scrollTop = elementTop - ( viewportHeight / 2 ) + ( elementHeight / 2 ) ;
267+ container . scrollTop = scrollTop ;
268+
269+ }
270+
259271 function extractQuery ( ) {
260272
261273 const search = window . location . search ;
@@ -501,7 +513,7 @@ <h1><a href="https://threejs.org">three.js</a></h1>
501513 pageInfo . linkElement . classList . add ( 'selected' ) ;
502514
503515 // Scroll the link into view
504- pageInfo . linkElement . scrollIntoView ( { block : 'center' } ) ;
516+ scrollIntoViewVertical ( pageInfo . linkElement ) ;
505517
506518 }
507519
@@ -590,7 +602,7 @@ <h1><a href="https://threejs.org">three.js</a></h1>
590602 // Only scroll if this is not a user click (user clicks handle their own smooth scrolling)
591603 if ( ! isUserClick ) {
592604
593- pageLink . linkElement . scrollIntoView ( { block : 'center' } ) ;
605+ scrollIntoViewVertical ( pageLink . linkElement ) ;
594606
595607 }
596608
0 commit comments