coherent-gameface-interaction-manager
Version:
Library for the most common UI interactions
75 lines (67 loc) • 2.55 kB
HTML
<!--Copyright (c) Coherent Labs AD. All rights reserved. Licensed under the MIT License. See License.txt in the project root for license information. -->
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Spatial Navigation Demo</title>
<style>
body {
background-color: white;
display: flex;
align-items: center;
justify-content: center;
flex-direction: column;
}
.container {
width: 400px;
display: flex;
flex-wrap: wrap;
}
.square {
width: 100px;
height: 100px;
background-color: cadetblue;
border: 1px solid black;
box-sizing: border-box;
}
.square:focus {
background-color: crimson;
}
.disabled {
filter: grayscale(1);
}
</style>
</head>
<body>
<h2>Move the focus around by using the keyboard arrow keys or the gamepad d-pad</h2>
<h2>Notice how the disabled elements are not focused</h2>
<div class="container">
<div class="square">1</div>
<div class="square disabled" disabled>2</div>
<div class="square">3</div>
<div class="square">4</div>
<div class="square">5</div>
<div class="square">6</div>
<div class="square">7</div>
<div class="square disabled" disabled>8</div>
<div class="square">9</div>
<div class="square">10</div>
<div class="square">11</div>
<div class="square">12</div>
<div class="square">13</div>
<div class="square">14</div>
<div class="square">15</div>
<div class="square disabled" disabled>16</div>
</div>
<script src="../../dist/spatial-navigation.js"></script>
<script src="../../dist/gamepad.js"></script>
<script>
spatialNavigation.init(['.square']);
spatialNavigation.focusFirst();
gamepad.enabled = true;
gamepad.lessSensitive = true;
</script>
</body>
</html>