键盘导航为cbp全宽滑块

时间:2015-12-29 07:20:19

标签: javascript jquery css slider keyboard-navigation

试过这个JS-FIDDLE但是没有成功。有人可以提供帮助,如何启用此滑块的键盘导航。

_toggleNavControls : function() {

        // if the current item is the first one in the list, the left arrow is not shown
        // if the current item is the last one in the list, the right arrow is not shown
        switch( this.current ) {
            case 0 : this.$navNext.show(); this.$navPrev.hide(); break;
            case this.itemsCount - 1 : this.$navNext.hide(); this.$navPrev.show(); break;
            default : this.$navNext.show(); this.$navPrev.show(); break;
        }
        // highlight navigation dot
        this.$navDots.eq( this.old ).removeClass( 'cbp-fwcurrent' ).end().eq( this.current ).addClass( 'cbp-fwcurrent' );

    }

Anyhelp将不胜感激。

1 个答案:

答案 0 :(得分:2)

see demo

您需要在_initEvents函数中绑定文档上的keydown事件,并观察左右箭头键是否被按下:

$(document).keydown(keyHandler);

function keyHandler(event)  { 
        if (event.keyCode === 39) {

           if(self.$navNext.is(":visible")) self.$navNext.trigger("click.cbpFWSlider");
            return false;
          } else if (event.keyCode === 37) {
            if(self.$navPrev.is(":visible")) self.$navPrev.trigger("click.cbpFWSlider");
            return false;
          }

    };

P.S。在Jsfiddle中,不要忘记通过点击它将焦点放在预览区域 - 右下角,以便正在观看按键。

相关问题