Skip to content

Instantly share code, notes, and snippets.

@mattborn
Created February 3, 2020 23:04
Show Gist options
  • Save mattborn/f2a84930bee0a0ca80b7fdd89d0ddce3 to your computer and use it in GitHub Desktop.
Save mattborn/f2a84930bee0a0ca80b7fdd89d0ddce3 to your computer and use it in GitHub Desktop.
Cycle through objects with keyboard trigger
<!doctype html>
<html>
<head>
<title>Rota</title>
</head>
<body>
<script src="Rota.js"></script>
</body>
</html>
const projects = [
{
name: 'Markless',
data: [],
},
{
name: 'Button',
data: [],
},
{
name: 'Artemis',
data: [
],
},
]
let state = {
selected_project: 0,
}
function render() {
console.log(projects[state.selected_project])
}
document.addEventListener('keydown', (e) => {
// cycle through projects, first dimension
if (e.which === 80) {
if (state.selected_project === projects.length - 1) {
state.selected_project = 0
} else {
state.selected_project++
}
render()
}
})
render()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment