mirror of
https://github.com/storytold/spark.git
synced 2026-10-09 00:09:53 +00:00
Tweak examples for mobile (#14)
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Forge • Environment Mapping</title>
|
<title>Forge • Environment Mapping</title>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Forge • Hello World</title>
|
<title>Forge • Hello World</title>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
|
|||||||
@@ -2,11 +2,13 @@
|
|||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Forge • Multiple Splats</title>
|
<title>Forge • Multiple Splats</title>
|
||||||
<link rel="stylesheet" href="style.css">
|
<link rel="stylesheet" href="style.css">
|
||||||
</head>
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
<a href="#" id="mobile_button">Menu</a>
|
||||||
<div id="menu">
|
<div id="menu">
|
||||||
<div class="border">
|
<div class="border">
|
||||||
<div class="border">
|
<div class="border">
|
||||||
@@ -48,6 +50,12 @@
|
|||||||
document.getElementById('menu_list').appendChild(el);
|
document.getElementById('menu_list').appendChild(el);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Setup mobile menu button
|
||||||
|
let IS_MOBILE = 'ontouchstart' in window || navigator.msMaxTouchPoints;
|
||||||
|
document.getElementById('mobile_button').addEventListener('click', () => {
|
||||||
|
document.getElementById('menu').classList.toggle('visible');
|
||||||
|
});
|
||||||
|
|
||||||
const scene = new THREE.Scene();
|
const scene = new THREE.Scene();
|
||||||
const renderer = new THREE.WebGLRenderer();
|
const renderer = new THREE.WebGLRenderer();
|
||||||
renderer.shadowMap.enabled = true;
|
renderer.shadowMap.enabled = true;
|
||||||
@@ -58,6 +66,14 @@
|
|||||||
const camera = new THREE.PerspectiveCamera(65, window.innerWidth / window.innerHeight, 0.1, 1000);
|
const camera = new THREE.PerspectiveCamera(65, window.innerWidth / window.innerHeight, 0.1, 1000);
|
||||||
camera.position.set(0, 0.9, -1.2);
|
camera.position.set(0, 0.9, -1.2);
|
||||||
|
|
||||||
|
// handle windows resize
|
||||||
|
window.addEventListener('resize', onWindowResize, false);
|
||||||
|
function onWindowResize() {
|
||||||
|
camera.aspect = window.innerWidth / window.innerHeight;
|
||||||
|
camera.updateProjectionMatrix();
|
||||||
|
renderer.setSize(window.innerWidth, window.innerHeight);
|
||||||
|
}
|
||||||
|
|
||||||
// Setup mouse controls to orbit the camera around
|
// Setup mouse controls to orbit the camera around
|
||||||
const controls = new OrbitControls(camera, renderer.domElement);
|
const controls = new OrbitControls(camera, renderer.domElement);
|
||||||
controls.target.set(0.2, 0, 0);
|
controls.target.set(0.2, 0, 0);
|
||||||
@@ -80,7 +96,7 @@
|
|||||||
|
|
||||||
// Transition length in frames.
|
// Transition length in frames.
|
||||||
// Two transitions: one for fading out the old food, another for fading in the next one
|
// Two transitions: one for fading out the old food, another for fading in the next one
|
||||||
const TRANSITION_LENGTH = 60;
|
const TRANSITION_LENGTH = IS_MOBILE ? 30 : 60;
|
||||||
// Transition timers. `null` if transition is not active
|
// Transition timers. `null` if transition is not active
|
||||||
let fadeOutTime = null;
|
let fadeOutTime = null;
|
||||||
let fadeInTime = null;
|
let fadeInTime = null;
|
||||||
@@ -93,9 +109,6 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
// show menu
|
|
||||||
document.getElementById('menu').style.display = 'block';
|
|
||||||
|
|
||||||
// Setup lighting
|
// Setup lighting
|
||||||
const spotLight = new THREE.SpotLight(0xffcc88);
|
const spotLight = new THREE.SpotLight(0xffcc88);
|
||||||
spotLight.position.set(0, 1, 0);
|
spotLight.position.set(0, 1, 0);
|
||||||
@@ -135,6 +148,10 @@
|
|||||||
floor.position.set(0, -1.397, 0);
|
floor.position.set(0, -1.397, 0);
|
||||||
scene.add(floor);
|
scene.add(floor);
|
||||||
|
|
||||||
|
// Show menu
|
||||||
|
document.getElementById('menu').classList.add('visible');
|
||||||
|
if (IS_MOBILE) document.getElementById('mobile_button').classList.add('visible');
|
||||||
|
|
||||||
// Load first food by default
|
// Load first food by default
|
||||||
switchToFood(0);
|
switchToFood(0);
|
||||||
|
|
||||||
@@ -208,6 +225,9 @@
|
|||||||
|
|
||||||
scene.add(nextFood);
|
scene.add(nextFood);
|
||||||
|
|
||||||
|
// Hide menu if on mobile
|
||||||
|
if (IS_MOBILE) document.getElementById('menu').classList.remove('visible');
|
||||||
|
|
||||||
// toggle menu item
|
// toggle menu item
|
||||||
const menu_items = document.getElementById('menu_list').children;
|
const menu_items = document.getElementById('menu_list').children;
|
||||||
for (let i = 0; i < menu_items.length; i++) {
|
for (let i = 0; i < menu_items.length; i++) {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
body {
|
body {
|
||||||
margin: 0;
|
margin: 0;
|
||||||
background-color: black;
|
background-color: black;
|
||||||
|
font-family: serif;
|
||||||
}
|
}
|
||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
@@ -65,12 +66,12 @@ h3 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#menu a.active::before {
|
#menu a.active::before {
|
||||||
content: "🙜 ";
|
content: "● ";
|
||||||
font-weight: 100;
|
font-weight: 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
#menu a.active::after {
|
#menu a.active::after {
|
||||||
content: " 🙟";
|
content: " ● ";
|
||||||
font-weight: 100;
|
font-weight: 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,3 +91,40 @@ h3 {
|
|||||||
top: 40vh;
|
top: 40vh;
|
||||||
left: 45vw;
|
left: 45vw;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* mobile */
|
||||||
|
#mobile_button {
|
||||||
|
text-decoration: none;
|
||||||
|
color: black;
|
||||||
|
padding: 10px 15px;
|
||||||
|
background-color: burlywood;
|
||||||
|
text-align: center;
|
||||||
|
font-family: serif;
|
||||||
|
font-style: italic;
|
||||||
|
font-size: 1.5rem;
|
||||||
|
position: absolute;
|
||||||
|
border-radius: 1rem;
|
||||||
|
margin: 1rem;
|
||||||
|
opacity: 0.8;
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.visible {
|
||||||
|
display: block !important;
|
||||||
|
}
|
||||||
|
|
||||||
|
@media (any-pointer: coarse) {
|
||||||
|
#menu {
|
||||||
|
display: none;
|
||||||
|
top: 4.5rem;
|
||||||
|
left: 0;
|
||||||
|
font-size: 1rem;
|
||||||
|
line-height: 3.2vh;
|
||||||
|
width: 82%;
|
||||||
|
margin: 0 auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
h1 {
|
||||||
|
font-size: 4rem;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Forge • Multiple Splats</title>
|
<title>Forge • Multiple Splats</title>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Forge • Multiple Viewpoints</title>
|
<title>Forge • Multiple Viewpoints</title>
|
||||||
<link rel="stylesheet" href="style.css">
|
<link rel="stylesheet" href="style.css">
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ body {
|
|||||||
header {
|
header {
|
||||||
margin: 0 auto;
|
margin: 0 auto;
|
||||||
padding: 10px 0;
|
padding: 10px 0;
|
||||||
min-width: 400px;
|
min-width: 300px;
|
||||||
width: 50%;
|
width: 50%;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Forge • Procedural Splats</title>
|
<title>Forge • Procedural Splats</title>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
@@ -138,4 +139,4 @@
|
|||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Forge • Raycasting</title>
|
<title>Forge • Raycasting</title>
|
||||||
<style>
|
<style>
|
||||||
body {
|
body {
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Forge • VFX Dynamic Lighting</title>
|
<title>Forge • VFX Dynamic Lighting</title>
|
||||||
<style>
|
<style>
|
||||||
html,
|
html,
|
||||||
@@ -22,7 +23,6 @@
|
|||||||
position: absolute;
|
position: absolute;
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
margin: 1rem 2rem;
|
margin: 1rem 2rem;
|
||||||
display: block;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
label {
|
label {
|
||||||
@@ -31,6 +31,8 @@
|
|||||||
color: white;
|
color: white;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
margin-right: 2rem;
|
margin-right: 2rem;
|
||||||
|
margin-bottom: 0.5rem;
|
||||||
|
display: inline-block;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
|
|||||||
Reference in New Issue
Block a user