使用鼠标左,右,上,下与galleria javascript

时间:2009-10-03 13:50:55

标签: jquery keyboard galleria

我正在玩这个图书馆,Galleria,非常整洁。这是下面的网址:

http://devkick.com/lab/galleria/

但无论如何我无法通过键盘(右,左等)从一个缩略图移动到另一个缩略图。 。有没有人使用这个图书馆并使其工作?

4 个答案:

答案 0 :(得分:5)

$(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,它有效。

我创建了一个testpage,已经在IE 8,Chrome 3,Opera 10和Firefox 3.5中进行了测试。它适用于所有这些。测试页基于this page,仅添加了上述代码。

答案 1 :(得分:2)

我只绑定左箭头和右箭头,因为用户经常使用向上和向下箭头进行导航,但如果要使用向上和向下箭头,则可以取消注释这些行:

<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;
        }
    });
});

答案 2 :(得分:2)

以前的答案在我的案例中不起作用。我没有使用文档事件,而是使用了Galleria API的内置attachKeyboard()功能。

代码在galleria调用的init中设置:

  

.galleria({

extend:function() {
    this.attachKeyboard({
        left: this.prev,
        right: this.next,
        up: function() {
            Galleria.log('up key pressed');
        }
    });
} });

请注意,我在Get Satisfaction forum here中找到了此解决方案。

我希望这有助于其他人。

答案 3 :(得分:1)

同样来自Get Satisfaction forums

在galleria.classic.js初始化函数

中添加了这段代码
this.attachKeyboard({
  left: this.prev,
  right: this.next
}); 

像魅力一样!