Hi, I'm using the following code to enable the user to show or hide a photo description (#photoinfo) and a menu (.slidetable) using the up and down arrow keys. If one of these two divs is already open, pressing the opposite arrow closes that div before opening the other.
$(document).unbind('keypress');
$(document).keydown(function(event) {
switch (event.keyCode) {
case 38:
if ($('#photoinfo').is(".open")) {
closeInfo();
}
else if ($('.slidetable').is(".open")) {
closeSlide2();
openInfo();
}
else {
openInfo();
}
break;
case 40:
if ($('.slidetable').is(".open")) {
closeSlide();
}
else if ($('#photoinfo').is(".open")) {
closeInfo();
openSlide();
}
else {
openSlide();
}
break;
}
return false;
});
It seems to work, only the problem is if two arrows are pressed at the same time, or one after the other, both divs open, overlapping eachother. I'm looking for a way to essentially unbind the keydown function after the first animation initiates, and rebind the keydown function once it finishes. I'm a jquery novice, so maybe this isnt the best way of doing this. What is the easiest way of preventing the other function from firing during the animation?
Thanks