Browse Source

Examples: Mobile friendly.

Mr.doob 10 years ago
parent
commit
cf04c59e41
2 changed files with 182 additions and 80 deletions
  1. 61 54
      docs/index.html
  2. 121 26
      examples/index.html

+ 61 - 54
docs/index.html

@@ -2,9 +2,10 @@
 <html lang="en">
 	<head>
 		<meta charset="utf-8">
-		<title>three.js - documentation</title>
+		<title>three.js / documentation</title>
 		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
 		<style>
+
 			@font-face {
 				font-family: 'inconsolata';
 				src: url('files/inconsolata.woff') format('woff');
@@ -12,7 +13,9 @@
 				font-style: normal;
 			}
 
-			*{ box-sizing: border-box;}
+			*{
+				box-sizing: border-box;
+			}
 
 			html {
 				height: 100%;
@@ -20,8 +23,7 @@
 
 			body {
 				background-color: #ffffff;
-				margin: 0;
-				padding: 0 0 0 260px;
+				margin: 0px;
 				height: 100%;
 				color: #555;
 				font-family: 'inconsolata';
@@ -35,7 +37,7 @@
 				text-decoration: none;
 			}
 
-			#panel	{
+			#panel {
 				position: fixed;
 				left: 0px;
 				width: 260px;
@@ -77,8 +79,10 @@
 				}
 
 			#viewer {
+				position: absolute;
 				border: 0px;
-				width: 100%;
+				left: 260px;
+				width: calc(100% - 260px);
 				height: 100%;
 				overflow: auto;
 			}
@@ -90,6 +94,7 @@
 			.filterBlock p {
 				margin: 0;
 			}
+
 			#filterInput {
 				width: 100%;
 				padding: 5px;
@@ -98,11 +103,13 @@
 				outline: none;
 				border: 1px solid #dedede;
 			}
+
 			#filterInput:focus{
 				border: 1px solid #2194CE;
 			}
+
 			#clearFilterButton {
-				position: absolute; 
+				position: absolute;
 				right: 6px;
 				top: 50%;
 				margin-top: -8px;
@@ -115,39 +122,47 @@
 				padding-top: 7px;
 				opacity: .5;
 			}
-			#clearFilterButton:hover{
+
+			#clearFilterButton:hover {
 				opacity: 1;
 			}
-			.filtered{
+
+			.filtered {
 				display: none;
 			}
-			#panel li b{
+
+			#panel li b {
 				font-weight: bold;
 			}
-			#expandButton{
+
+			/* mobile */
+
+			#expandButton {
 				display: none;
 				position: absolute;
 				right: 20px;
 				top: 12px;
 				width: 32px;
 				height: 32px;
-				background-color: #2194CE;
-			}
-			#expandButton span{
-				height: 3px;
-				background-color: white;
-				width: 16px;
-				position: absolute;
-				left: 8px;
-				top: 8px;
-			}
-			#expandButton span:nth-child(1) {
-				top: 14px;
-			}
-			#expandButton span:nth-child(2) {
-				top: 20px;
-				width: 12px;
 			}
+
+				#expandButton span {
+					height: 2px;
+					background-color: #2194CE;
+					width: 16px;
+					position: absolute;
+					left: 8px;
+					top: 10px;
+				}
+
+				#expandButton span:nth-child(1) {
+					top: 16px;
+				}
+
+				#expandButton span:nth-child(2) {
+					top: 22px;
+				}
+
 			@media all and ( max-width: 640px ) {
 				#panel{
 					position: absolute;
@@ -160,18 +175,24 @@
 					overflow: hidden;
 					border-bottom: 1px solid #dedede;
 				}
+				#panel h1{
+					margin-top: 20px;
+					margin-bottom: 20px;
+				}
 				#content{
 					overflow: auto;
 					position: absolute;
 					left: 0;
-					top: 120px;
+					top: 90px;
 					right: 0;
 					bottom: 0;
 				}
 				#viewer{
 					position: absolute;
 					left: 0;
-					top: 48px;
+					top: 56px;
+					width: 100%;
+					height: calc(100% - 56px);
 				}
 				#expandButton{
 					display: block;
@@ -179,13 +200,6 @@
 				#panel.collapsed{
 					height: 56px;
 				}
-				#panel h1{
-					margin-top: 20px;
-					margin-bottom: 20px;
-				}
-				#content{
-					top: 90px;
-				}
 			}
 		</style>
 	</head>
@@ -205,16 +219,17 @@
 		</script>
 
 		<div id="panel" class="collapsed">
+			<h1><a href="http://threejs.org">three.js</a> / docs</h1>
 			<a id="expandButton" href="#" >
-				<span></span><span></span><span></span>
+				<span></span>
+				<span></span>
+				<span></span>
 			</a>
-			<h1><a href="http://threejs.org">three.js</a> / docs</h1>
 			<div class="filterBlock" >
 				<input type="text" id="filterInput" placeholder="Type to filter"/>
 				<a href="#" id="clearFilterButton" >x</a>
 			</div>
-			<div id="content" >
-			</div>
+			<div id="content"></div>
 		</div>
 		<iframe id="viewer"></iframe>
 
@@ -223,23 +238,15 @@
 			var panel = document.getElementById( 'panel' );
 			var viewer = document.getElementById( 'viewer' );
 
-			var clearFilterButton = document.getElementById( 'clearFilterButton' );
-			var filterInput = document.getElementById( 'filterInput' );
-			//filterInput.focus();
-
-			panel.addEventListener( 'click', function( e ) {
-				//filterInput.focus();
-				e.preventDefault();
-			} );
-
-			document.getElementById( 'expandButton' ).addEventListener( 'click', function( e ) {
+			var expandButton = document.getElementById( 'expandButton' );
+			expandButton.addEventListener( 'click', function ( event ) {
 				panel.classList.toggle( 'collapsed' );
-				if( !panel.classList.contains( 'collapsed' ) ) {
-					//filterInput.focus();
-				}
-				e.preventDefault();
+				event.preventDefault();
 			} );
 
+			var filterInput = document.getElementById( 'filterInput' );
+			var clearFilterButton = document.getElementById( 'clearFilterButton' );
+
 			var DELIMITER = '/';
 			var MEMBER_DELIMITER = '.';
 			var nameCategoryMap = {};

+ 121 - 26
examples/index.html

@@ -1,8 +1,9 @@
 <!DOCTYPE html>
 <html lang="en">
 	<head>
-		<title>three.js - examples</title>
 		<meta charset="utf-8">
+		<title>three.js / examples</title>
+		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
 		<style>
 
 			@font-face {
@@ -12,11 +13,22 @@
 				font-style: normal;
 			}
 
+			*{
+				box-sizing: border-box;
+			}
+
+			html {
+				height: 100%;
+			}
+
 			body {
 				background-color: #ffffff;
 				margin: 0px;
+				height: 100%;
+				color: #555;
 				font-family: 'inconsolata';
 				font-size: 15px;
+				line-height: 18px;
 				overflow: hidden;
 			}
 
@@ -25,51 +37,54 @@
 				text-decoration: none;
 			}
 
-			h1 {
-				margin-top: 30px;
-				margin-bottom: 40px;
-				font-size: 25px;
-				font-weight: normal;
-			}
-
-			h2 {
-				font-size: 20px;
-				font-weight: normal;
-			}
-
 			#panel {
-				position: absolute;
+				position: fixed;
+				left: 0px;
 				width: 310px;
 				height: 100%;
-				overflow: scroll;
+				overflow: auto;
 				background: #fafafa;
 			}
 
-				#panel #list {
+				#panel h1 {
+					margin-top: 30px;
+					margin-bottom: 40px;
+					margin-left: 20px;
+					font-size: 25px;
+					font-weight: normal;
+				}
+
+				#panel h2 {
+					font-size: 20px;
+					font-weight: normal;
+				}
+
+				#panel #content {
 					padding: 0px 20px;
 					line-height: 18px;
 				}
 
-				#panel #list .link {
+				#panel #content .link {
 					color: #2194CE;
 					text-decoration: none;
 					cursor: pointer;
 				}
 
-				#panel #list .selected {
+				#panel #content .selected {
 					color: #ff0000;
 				}
 
-					#panel #list .link:hover {
+					#panel #content .link:hover {
 						text-decoration: underline;
 					}
 
 			#viewer {
 				position: absolute;
+				border: 0px;
 				left: 310px;
 				width: calc(100% - 310px);
 				height: 100%;
-				border: 0px;
+				overflow: auto;
 			}
 
 			#button {
@@ -87,6 +102,73 @@
 					opacity: 1;
 				}
 
+			/* mobile */
+
+			#expandButton {
+				display: none;
+				position: absolute;
+				right: 20px;
+				top: 12px;
+				width: 32px;
+				height: 32px;
+			}
+
+				#expandButton span {
+					height: 2px;
+					background-color: #2194CE;
+					width: 16px;
+					position: absolute;
+					left: 8px;
+					top: 10px;
+				}
+
+				#expandButton span:nth-child(1) {
+					top: 16px;
+				}
+
+				#expandButton span:nth-child(2) {
+					top: 22px;
+				}
+
+			@media all and ( max-width: 640px ) {
+				#panel{
+					position: absolute;
+					left: 0;
+					top: 0;
+					height: 480px;
+					width: 100%;
+					right: 0;
+					z-index: 100;
+					overflow: hidden;
+					border-bottom: 1px solid #dedede;
+				}
+				#panel h1{
+					margin-top: 20px;
+					margin-bottom: 20px;
+				}
+				#content{
+					overflow: auto;
+					position: absolute;
+					left: 0;
+					top: 60px;
+					right: 0;
+					bottom: 0;
+				}
+				#viewer{
+					position: absolute;
+					left: 0;
+					top: 56px;
+					width: 100%;
+					height: calc(100% - 56px);
+				}
+				#expandButton{
+					display: block;
+				}
+				#panel.collapsed{
+					height: 56px;
+				}
+			}
+
 		</style>
 	</head>
 	<body>
@@ -104,10 +186,14 @@
 
 		</script>
 
-		<div id="panel">
-			<div id="list">
-				<h1><a href="http://threejs.org">three.js</a> / examples</h1>
-			</div>
+		<div id="panel" class="collapsed">
+			<h1><a href="http://threejs.org">three.js</a> / examples</h1>
+			<a id="expandButton" href="#" >
+				<span></span>
+				<span></span>
+				<span></span>
+			</a>
+			<div id="content"></div>
 		</div>
 		<iframe id="viewer" allowfullscreen></iframe>
 
@@ -373,9 +459,17 @@
 
 		//
 
-		var list = document.getElementById( 'list' );
+		var content = document.getElementById( 'content' );
 		var viewer = document.getElementById( 'viewer' );
 
+		var expandButton = document.getElementById( 'expandButton' );
+		expandButton.addEventListener( 'click', function ( event ) {
+			panel.classList.toggle( 'collapsed' );
+			event.preventDefault();
+		} );
+
+		// iOS8 workaround
+
 		if ( /(iPad|iPhone|iPod)/g.test( navigator.userAgent ) ) {
 
 			viewer.addEventListener( 'load', function ( event ) {
@@ -388,7 +482,7 @@
 		}
 
 		var container = document.createElement( 'div' );
-		list.appendChild( container );
+		content.appendChild( container );
 
 		var button = document.createElement( 'div' );
 		button.id = 'button';
@@ -428,6 +522,7 @@
 					div.textContent = name;
 					div.addEventListener( 'click', function () {
 
+						panel.classList.toggle( 'collapsed' );
 						load( file );
 
 					} );