浏览代码

Improvements to examples viewer.

Mr.doob 12 年之前
父节点
当前提交
bd897c9197
共有 1 个文件被更改,包括 60 次插入26 次删除
  1. 60 26
      examples/index.html

+ 60 - 26
examples/index.html

@@ -24,28 +24,11 @@
 
 
 			}
 			}
 
 
-			a {
-
-				color: #2194CE;
-				text-decoration: none;
-
-			}
-
-				a:hover {
-
-					text-decoration: underline;
-
-				}
-
-				a:active {
-
-					color: #ff8888;
-
-				}
-
 			h1 {
 			h1 {
+
 				font-size: 25px;
 				font-size: 25px;
 				font-weight: normal;
 				font-weight: normal;
+
 			}
 			}
 
 
 			#panel {
 			#panel {
@@ -64,6 +47,26 @@
 
 
 				}
 				}
 
 
+				#panel #list .link {
+
+					color: #2194CE;
+					text-decoration: none;
+					cursor: pointer;
+
+				}
+
+				#panel #list .selected {
+
+					color: #ff0000;
+
+				}
+
+					#panel #list .link:hover {
+
+						text-decoration: underline;
+
+					}
+
 			#viewer {
 			#viewer {
 
 
 				position: absolute;
 				position: absolute;
@@ -81,6 +84,7 @@
 		<div id="panel">
 		<div id="panel">
 			<div id="list">
 			<div id="list">
 				<h1>three.js examples</h1>
 				<h1>three.js examples</h1>
+				<br />
 			</div>
 			</div>
 		</div>
 		</div>
 		<iframe id="viewer"></iframe>
 		<iframe id="viewer"></iframe>
@@ -297,22 +301,52 @@
 
 
 		];
 		];
 
 
+		//
+
 		var list = document.getElementById( 'list' );
 		var list = document.getElementById( 'list' );
+		var viewer = document.getElementById( 'viewer' );
 
 
 		var container = document.createElement( 'div' );
 		var container = document.createElement( 'div' );
 		list.appendChild( container );
 		list.appendChild( container );
 
 
+		var divs = {};
+		var SELECTED = null;
+
 		for ( var i = 0; i < files.length; i ++ ) {
 		for ( var i = 0; i < files.length; i ++ ) {
 
 
-			var file = files[ i ];
+			( function ( file ) {
+
+				var div = document.createElement( 'div' );
+				div.className = 'link';
+				div.textContent = file;
+				div.addEventListener( 'click', function () {
+
+					load( file );
+
+				} );
+				container.appendChild( div );
+
+				divs[ file ] = div;
+
+			} )( files[ i ] );
+
+		}
+
+		var load = function ( file ) {
+
+			if ( SELECTED !== null ) SELECTED.className = 'link';
+
+			SELECTED = divs[ file ];
+			SELECTED.className = 'link selected';
+
+			window.location.hash = file;
+			viewer.src = file + '.html';
+
+		};
 
 
-			var link = document.createElement( 'a' );
-			link.href = file + '.html';
-			link.textContent = file;
-			link.target = 'viewer';
-			container.appendChild( link );
+		if ( window.location.hash !== '' ) {
 
 
-			container.appendChild( document.createElement( 'br' ) );
+			load( window.location.hash.substring( 1 ) );
 
 
 		}
 		}