我正在玩这个库,Galleria,它非常整洁。这是下面的网址:
http://devkick.com/lab/galleria/
但无论如何我都看不到用键盘(右、左等)从一个缩略图移动到另一个缩略图。. 有没有人使用过这个库并让它工作?
我正在玩这个库,Galleria,它非常整洁。这是下面的网址:
http://devkick.com/lab/galleria/
但无论如何我都看不到用键盘(右、左等)从一个缩略图移动到另一个缩略图。. 有没有人使用过这个库并让它工作?
$(document).bind("keydown", function(e){
if(e.keyCode== 37){
$.galleria.prev();
}else if(e.keyCode== 38){
$.galleria.next();
}else if(e.keyCode== 39){
$.galleria.next();
}else if(e.keyCode== 40){
$.galleria.prev();
}else{
return true;
}
return false;
});
似乎按键在 IE 中不起作用。我将其更改为keydown,它有效。
我创建了一个已在 IE 8、Chrome 3、Opera 10 和 Firefox 3.5 中测试过的测试页。它适用于所有人。测试页基于此页面,仅添加了上面的代码。
我只绑定左右箭头,因为用户经常使用向上和向下箭头进行导航,但如果你想使用向上和向下,你可以取消注释这些行:
<script type="text/javascript">
$(document).ready(function($) {
$('ul.gallery_unstyled').addClass('gallery');
$('ul.gallery').galleria({
history: false,
clickNext: true,
insert: '#main_image',
onImage: function(image, caption, thumb) {
// add a title for the clickable image
image.attr('title', 'Next image >>');
}
});
$(document).keydown(function(e) {
switch (e.keyCode) {
case 37: // left arrow
//case 38: // up arrow
$.galleria.prev();
break;
case 39: // right arrow
//case 40: // down arrow
$.galleria.next();
break;
}
});
});
以前的答案在我的情况下不起作用。我没有使用文档事件,而是利用attachKeyboard()
了 Galleria API 的内置功能。
代码在 Galleria 调用的 init 中设置:
.画廊({
extend:function() { this.attachKeyboard({ left: this.prev, right: this.next, up: function() { Galleria.log('up key pressed'); } }); } });
请注意,我在此处的 Get Satisfaction 论坛中找到了此解决方案。
我希望这对其他人有帮助。
在 Galleria.classic.js 的 init 函数中添加了这段代码
this.attachKeyboard({
left: this.prev,
right: this.next
});
奇迹般有效!