JQuery SmoothDivScroll和箭头键

时间:2013-01-04 11:50:52

标签: jquery html smooth-scrolling

我需要让JQuery SmoothDivScroll plugin与箭头键盘键一起使用 - 左右键应滚动内容,就像鼠标滚轮和热点一样。如何使用自定义JQuery代码实现此目的?

1 个答案:

答案 0 :(得分:0)

我解决了它。解决方案并不漂亮,但有效。此外,应将代码段移动到单独的代码文件中。 TODO:重构。

1)“scrollableArea”div应具有属性 tabindex 。 2)在插件代码文件中,下面的代码语句应添加到 _create 函数中。它应该被重构,因为目前它是从 mousewheel 事件处理程序

中大量复制的
r.data("scrollableArea").keydown(function (e) {

            var arrow = { left: 37, up: 38, right: 39, down: 40 };
            var i,s,u;

            switch (e.keyCode || e.which) {

                case arrow.left:
                    i = 1;
                    s = 0;
                    u = 1;
                    break;

                case arrow.right:
                    i = -1;
                    s = 0;
                    u = -1;
                    break;
            }

                if (r.data("enabled") && n.mousewheelScrolling.length > 0) {
                    var a;
                    n.mousewheelScrolling === "vertical" && u !== 0 ? (t.stopAutoScrolling(), e.preventDefault(), a = Math.round(n.mousewheelScrollingStep * u * -1), t.move(a)) :
                    n.mousewheelScrolling === "horizontal" && s !== 0 ? (t.stopAutoScrolling(), e.preventDefault(), a = Math.round(n.mousewheelScrollingStep * s * -1), t.move(a)) :
                        n.mousewheelScrolling === "allDirections" && (t.stopAutoScrolling(), e.preventDefault(), a = Math.round(n.mousewheelScrollingStep * i * -1), t.move(a));
                }
            }),