快捷键功能完善

阅读更多

1)使用的快捷键插件:keypress-2.1.4.min.js

2)键盘的向上向下键盘,选择元素

/**

*up:键盘的向上

*down:键盘的向下 

*/

function up(obj,isChild){

    obj.removeClass("selected");

    var prev = obj.prev();

    prev.addClass('selected');

}

function down(obj,isChild){

    obj.removeClass("selected");

    var next = obj.next();

    next.addClass('selected');

}

 

** hidden(prev,'up');    up_down_event(prev,isChild);代码可忽略(业务方面内容)

3)检测元素是否在可视区域  有滚动条

function hidden(obj,forword){

    var scrollWin = obj.parents('.gridScroller');

    var itemOffsetTop = obj.offset().top;

    var itemOuterHeight = obj.outerHeight();

 

    var winHeight = scrollWin.height();

    var winOffsetTop = scrollWin.offset().top;

 

 

    var scrolledHeight = scrollWin.scrollTop();

    var visibleHight = winHeight + winOffsetTop;

    var currentItemHeight = itemOffsetTop + itemOuterHeight;

 

    if(forword == 'down'){

        if(visibleHight < currentItemHeight){

      //to do 

             scrollWin.scrollTop(itemOuterHeight + scrolledHeight);

        }

    }else{//up

        currentItemHeight = currentItemHeight + scrolledHeight;

        if(visibleHight > currentItemHeight){

 //to do 

             scrollWin.scrollTop(scrolledHeight - itemOuterHeight);

        }

    }

}

ps:附件是快捷键的插件以及自己封装的功能实现。

  • js.rar (6.2 KB)
  • 下载次数: 0

你可能感兴趣的:(快捷键,javascript,键盘上下键)