فهرست منبع

New Docs: Use custom scrollIntoView.

Mr.doob 3 ماه پیش
والد
کامیت
64d3d97417
1فایلهای تغییر یافته به همراه16 افزوده شده و 4 حذف شده
  1. 16 4
      utils/docs/template/static/index.html

+ 16 - 4
utils/docs/template/static/index.html

@@ -7,7 +7,6 @@
 		<link rel="shortcut icon" href="/files/favicon_white.ico" media="(prefers-color-scheme: dark)"/>
 		<link rel="shortcut icon" href="/files/favicon_white.ico" media="(prefers-color-scheme: dark)"/>
 		<link rel="shortcut icon" href="/files/favicon.ico" media="(prefers-color-scheme: light)" />
 		<link rel="shortcut icon" href="/files/favicon.ico" media="(prefers-color-scheme: light)" />
 		<link rel="stylesheet" type="text/css" href="/files/main.css">
 		<link rel="stylesheet" type="text/css" href="/files/main.css">
-		<link type="text/css" rel="stylesheet" href="styles/page.css">
 		<!-- console sandbox -->
 		<!-- console sandbox -->
 		<script type="module">
 		<script type="module">
 			import * as THREE from '../build/three.module.js';
 			import * as THREE from '../build/three.module.js';
@@ -246,7 +245,7 @@
 					if ( fullPageName === selectedPage || pageName === selectedPage ) {
 					if ( fullPageName === selectedPage || pageName === selectedPage ) {
 
 
 						link.classList.add( 'selected' );
 						link.classList.add( 'selected' );
-						link.scrollIntoView( { block: 'center' } );
+						scrollIntoViewVertical( link );
 
 
 					}
 					}
 
 
@@ -256,6 +255,19 @@
 
 
 		}
 		}
 
 
+		function scrollIntoViewVertical( element ) {
+
+			const container = document.getElementById( 'content' );
+			const elementTop = element.offsetTop;
+			const elementHeight = element.offsetHeight;
+			const viewportHeight = window.innerHeight;
+
+			// Scroll to center the element vertically using viewport height
+			const scrollTop = elementTop - ( viewportHeight / 2 ) + ( elementHeight / 2 );
+			container.scrollTop = scrollTop;
+
+		}
+
 		function extractQuery() {
 		function extractQuery() {
 
 
 			const search = window.location.search;
 			const search = window.location.search;
@@ -501,7 +513,7 @@
 						pageInfo.linkElement.classList.add( 'selected' );
 						pageInfo.linkElement.classList.add( 'selected' );
 
 
 						// Scroll the link into view
 						// Scroll the link into view
-						pageInfo.linkElement.scrollIntoView( { block: 'center' } );
+						scrollIntoViewVertical( pageInfo.linkElement );
 
 
 					}
 					}
 
 
@@ -590,7 +602,7 @@
 					// Only scroll if this is not a user click (user clicks handle their own smooth scrolling)
 					// Only scroll if this is not a user click (user clicks handle their own smooth scrolling)
 					if ( ! isUserClick ) {
 					if ( ! isUserClick ) {
 
 
-						pageLink.linkElement.scrollIntoView( { block: 'center' } );
+						scrollIntoViewVertical( pageLink.linkElement );
 
 
 					}
 					}
 
 

粤ICP备19079148号