Anybody know to resolve this?
I just want to do a simple animation using js/css where the object starts in the middle of the screen. Upon right or left arrow keypress, the object then moves to either side of the screen for a few seconds and then returns to the middle of the screen.
For some reason I can hit right and it goes right and returns to the middle and left goes left and returns to the middle.
However, when I hit left twice in a row or right twice in a row, it won't trigger on the second keypress.
document.addEventListener('keydown', keyDownHandler, false);
function keyDownHandler(event) {
if(event.keyCode == 39) {
falcon.style.animation = "move_right 3s";
}
else if (event.keyCode == 37) {
falcon.style.animation = "move_left 3s";
}
}
CSS:
@keyframes move_right {
0% { left: 40%;}
50% { left: 80%;}
100% {left: 40%;}
}
@keyframes move_left {
0% { left: 40%;}
50% { left: 0%;}
100% { left: 40%;}
}