In my animation which is “raining” dots with random colors, I want to be able to change the colors by pressing ENTER. For keypress i’m using the following code:
$(document).keypress(function(event){
var keycode = (event.keyCode ? event.keyCode : event.which);
if(keycode == '13'){
// change variables for the colors
}
});
As I see it, it shouldn’t be anything wrong with the code, but nothing happens when pressing ENTER. I would be glad if someone could help me out here!
You can find the code here: http://jsfiddle.net/GsBcz/
Why binding an event on each animation call ? Also [event.which] is jQuery’s crossbrowser way to detect mouse and key events.
This should help,
Fiddle
HTML:
JAVASCRIPT:
CSS: