【问题标题】:using mouse left, right, up, down with galleria javascript使用鼠标左、右、上、下和 Galleria javascript
【发布时间】:2010-12-03 13:59:53
【问题描述】:

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

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

但无论如何我都看不到使用键盘(右、左等)从一个缩略图移动到另一个缩略图。 .有没有人用过这个库并让它工作?

【问题讨论】:

    标签: jquery keyboard galleria


    【解决方案1】:
    $(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,仅添加了上面的代码。

    【讨论】:

    • 这似乎没有任何作用。你有任何例子表明这个工作吗??
    【解决方案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;
            }
        });
    });
    

    【讨论】:

      【解决方案3】:

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

      代码是在 init 中为 Galleria 调用设置的:

      .galleria({

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

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

      我希望这对其他人有帮助。

      【讨论】:

        【解决方案4】:

        同样来自Get Satisfaction forums

        在 Galleria.classic.js 的 init 函数中添加了这段代码

        this.attachKeyboard({
          left: this.prev,
          right: this.next
        }); 
        

        像魅力一样工作!

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-12-22
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-01-05
          相关资源
          最近更新 更多