Slider with keypress control bugs when keys pressed to quickly.
Posted
by Jaybuz
on Stack Overflow
See other posts from Stack Overflow
or by Jaybuz
Published on 2010-06-13T16:56:48Z
Indexed on
2010/06/13
17:02 UTC
Read the original article
Hit count: 276
Hello, I've made a slider that uses the left and right arrow keys to move the slide but when pressed to quickly it will bug a little and I was wondering if it's possible to limit the amount of presses in say a second. You can see it here: {link}
$('#slider-nav div').click(function() {
$('#slider-nav div').removeClass('selected').addClass('');
$('#slider-nav div:eq('+($.jcarousel.intval($(this).text())-1)+')').addClass('selected');
})
// Allow left and right keys to control slider
$(document.documentElement).keypress(function(e) {
var code = (e.keyCode ? e.keyCode : e.which);
var direction = null;
// handle cursor keys
if (code == 37) { // left key
direction = 'prev';
}
else if (code == 39) { // right key
direction = 'next';
}
if (direction != null) {
$('#slider-nav div.selected')[direction]().click();
}
});
© Stack Overflow or respective owner