Skip to content

Instantly share code, notes, and snippets.

@e0da
Created January 10, 2014 06:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save e0da/8347849 to your computer and use it in GitHub Desktop.
Save e0da/8347849 to your computer and use it in GitHub Desktop.
<!doctype html>
<body>
<script>
(function () {
'use strict';
var currentColor, colors, style, FORWARD, BACK;
FORWARD = 1;
BACK = -1;
colors = [
'white',
'black',
'red',
'green',
'blue'
];
currentColor = 0;
style = document.body.style;
function changeColor(direction) {
style.backgroundColor = colors[Math.abs((currentColor += direction) % colors.length)];
}
document.body.addEventListener('keydown', function(evnt) {
switch (evnt.keyIdentifier) {
case 'Left':
changeColor(BACK);
break;
case 'Right':
changeColor(FORWARD);
break;
}
});
}());
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment