在幻灯片上添加按键
我目前正在使用 http://www.latercode.com/simple-slideshow/
我尝试通过按键(左/右键)来导航幻灯片。
请问有什么建议吗?
$('.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();} );
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();} );
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
event.KeyCode 适合您的需求
检查 此 url 并在内部使用 event.KeyCode myKeyUpHandler 方法。像alert(event.KeyCode) 这样的东西应该打印出你按下的键的unicode。获取左、右、上、下的unicode,然后在case-switch语句中获取它们以调用forward() back()等等
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
您必须将功能绑定到文档的 keypress/keydown 事件(取决于浏览器,请参阅 这个其他问题),并检查按下了哪个键:
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: