I am creating a slide show rotator for the website I am creating. The rotator itself works fine, but I'm trying to make the slide show slide forward / backward using the left / right keys on the keyboard. My code is:
$(document).keydown(function(e){ var currentPosition = 0; var slideWidth = 836; var slides = $('.slide'); var numberOfSlides = slides.length; var animLength = 600; if (e.keyCode == 37) { currentPosition = currentPosition-1; // Check to see if new position is unbounded, and wrap accordingly. checkForEnds(currentPosition); // Move slideInner using margin-left $('#slideInner').animate({ 'marginLeft' : slideWidth*(-currentPosition) }, animLength, 'easeOutExpo'); animLength=600; return false; } /*Same code for right button, removed to save space.*/ function checkForEnds(position){ // If left is clicked on first slide, wrap to end. if(position==-1){currentPosition = numberOfSlides-1, animLength=1000} // If right is clicked on last slide, wrap to beginning. if(position==numberOfSlides){currentPosition = 0, animLength=1000} } });
My code works fine, but only once. I can rotate the left one or once once, but after that I cannot reuse the same key until another one is pressed. I'm very new to Javascript input, is there a simple fix for this?
Here is a temporary site. This is a mess now, but I can take care of all the weird order of things and the layout of the problem is pretty good. http://technoheads.org/test/ice/
Salem source share