Created
February 3, 2020 23:04
-
-
Save mattborn/f2a84930bee0a0ca80b7fdd89d0ddce3 to your computer and use it in GitHub Desktop.
Cycle through objects with keyboard trigger
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<title>Rota</title> | |
</head> | |
<body> | |
<script src="Rota.js"></script> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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