Przeglądaj źródła

Examples: Fix sidebar scrolling to selected example (#33023)

sunag 5 dni temu
rodzic
commit
8e5dc00dd7
1 zmienionych plików z 13 dodań i 1 usunięć
  1. 13 1
      examples/index.html

+ 13 - 1
examples/index.html

@@ -103,7 +103,7 @@
 				if ( validRedirects.has( file ) === true ) {
 
 					selectFile( file );
-					links[ file ].scrollIntoView( { block: 'center' } );
+					updateLinkScroll();
 					viewer.src = validRedirects.get( file );
 					viewer.style.display = 'unset';
 
@@ -171,6 +171,7 @@
 
 				event.preventDefault();
 				panel.classList.toggle( 'open' );
+				updateLinkScroll();
 
 			} );
 
@@ -385,6 +386,17 @@
 
 		}
 
+		function updateLinkScroll() {
+
+			if ( selected !== null ) {
+
+				const link = links[ selected ];
+				content.scrollTop = link.offsetTop - content.offsetTop - ( content.clientHeight - link.offsetHeight ) / 2;
+
+			}
+
+		}
+
 		</script>
 		<template id="PlaceholderHTML">
 			<!DOCTYPE html>

粤ICP备19079148号