There is probably more than 1 error but you put this line :
window.addEventListener("keydown", explode);
before the variable explode
is set. Set explode before binding the event and more errors will show, you'll be able to start debuging.
Question
http://jsfiddle.net/58YWM/8/ here's the original fiddle.
I don't know why but the keydown wouldn't listen and it won't execute the function.
window.addEventListener("keydown", explode);
var contW = $('#container').width();
var contH = $('#container').height();
var explode;
$('.holder').keydown(explode=function(e) {
event = event || window.event;
if(keycode === 32){
for (var j = 1; j <= 3; j++){
var sourceX = (Math.random()*contW)%(contW>>1);
var sourceY = (Math.random()*contH)%(contH>>1);
var nTop = Math.floor((Math.random()*contW)%contW);
var nLeft = Math.floor(((Math.random()*contH)%contH));
var $child = $(this).clone();
$('#container').append($child);
$child.css({ top:sourceX, left: sourceY })
.animate({ opacity: 0.5, top: nTop+'px', left:nLeft+'px' }, 500)
.keydown(explode);
$(this).hide();
}
});
Solution
There is probably more than 1 error but you put this line :
window.addEventListener("keydown", explode);
before the variable explode
is set. Set explode before binding the event and more errors will show, you'll be able to start debuging.