0

I'm currently using simple slideshow from http://www.lateralcode.com/simple-slideshow/

I tried to make the keypress (left/right key) to navigate the slideshow.

Any advice please?

$('.ppt li:gt(0)').hide();$('.ppt li:last').addClass('last');$('.ppt li:first').addClass('first');$('#play').hide();
var cur = $('.ppt li:first');var interval;

$('#fwd').click( function() {goFwd();showPause();return false;} );
$('#back').click( function() {goBack();showPause();return false;} );
$('#stop').click( function() {stop();showPlay();return false;} );
$('#play').click( function() {start();showPause();return false;} );
function goFwd() {stop();forward();start();}
function goBack() {stop();back();start();}
function back() {cur.fadeOut( 1000 );if ( cur.attr('class') == 'first' )cur = $('.ppt li:last'); else cur = cur.prev(); cur.fadeIn( 1000 );}
function forward() { cur.fadeOut( 1000 ); if ( cur.attr('class') == 'last' ) cur = $('.ppt li:first'); else cur = cur.next(); cur.fadeIn( 1000 );}
function showPause() {$('#play').hide(); $('#stop').show(); } 
function showPlay() {$('#stop').hide();  $('#play').show(); }
function start() {interval = setInterval( "forward()", 3000 ); }
function stop() {clearInterval( interval );}
$(function() {start();} );

2 Answers2

0

event.KeyCode suits your needs

check this url and use event.KeyCode inside the myKeyUpHandler method. Something like alert(event.KeyCode) should print you the unicode of the key you pressed. Get the unicodes of left, right, up and down and then grab them in a case-switch statement to call forward() back() and so on

Samuele Mattiuzzo
  • 10,760
  • 5
  • 39
  • 63
0

You'll have to bind your functionalities to the keypress/keydown event of the document (depending on the browser, see this other question), and check which key was pressed:

function checkKey(e){
  switch (e.keyCode) {
    case 37: //left arrow
      //back();
      break;
    case 39: //right arrow
      //next();
      break;      
  }
}

if ($.browser.mozilla) {
  $(document).keypress (checkKey);
} else {
  $(document).keydown (checkKey);
}
Community
  • 1
  • 1
pau.moreno
  • 4,407
  • 3
  • 35
  • 37