【问题标题】:Pan mobile gesture in backbone.js using toe.js使用 toe.js 在bone.js 中平移移动手势
【发布时间】:2017-05-14 07:12:43
【问题描述】:

我正在开发一个Cordova 应用程序(使用backbone.jsrequirejs)并且我正在使用toe.js js 库(https://github.com/dantipa/toe.js)来扩展jQuerybackbone.js 事件,以便有一些移动手势,如swipetaptapswipe 手势效果很好,但我需要 drag 事件(pan 手势),所以我尝试像这样编辑库:

(function ($, touch, window, undefined) {
    var namespace = 'drag';
    var cfg = {
        distance: 5,
        direction: 'all'
    };
    touch.track(namespace, {
        touchstart: function (event, state, start) {
            state[namespace] = {
                finger: start.point.length
            };
        },
        touchmove: function (event, state, move) {
            // if another finger was used then increment the amount of fingers used
            state[namespace].finger = move.point.length > state[namespace].finger ? move.point.length : state[namespace].finger;
        },
        touchend: function (event, state, end) {
            var opt = $.extend(cfg, event.data),
                duration,
                distance;

            // calc
            duration = touch.calc.getDuration(state.start, end);
            distance = touch.calc.getDistance(state.start.point[0], end.point[0]);

            // check if the swipe was valid
            if (distance > opt.distance) {

                state[namespace].angle = touch.calc.getAngle(state.start.point[0], end.point[0]);
                state[namespace].direction = touch.calc.getDirection(state[namespace].angle);
                state[namespace].distance = distance;

                // fire if the amount of fingers match
                if (opt.direction === 'all' || state[namespace].direction === opt.direction) {
                    $(event.target).trigger($.Event(namespace, touch.addEventParam(state.start, state[namespace])));
                }
            }
        }
    });
}(jQuery, jQuery.toe, this));

我不确定这是重现 drag 事件的好方法,所以你能帮我解决这个问题吗?

我需要那个事件来重现移动侧边栏菜单滑动效果:

我该怎么做? 附:我尝试将toe.js 替换为具有所有手势事件的hammer.js (https://hammerjs.github.io/),但在使用requirejs 将其与backbone.js 事件集成时遇到了问题。

谢谢

【问题讨论】:

    标签: javascript jquery backbone.js requirejs gesture


    【解决方案1】:

    Hammer.js 有一个 jQuery 扩展:http://hammerjs.github.io/jquery-plugin/ 如果你使用它而不是原生版本,你可能不会遇到与骨干事件集成的问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-11-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-27
      相关资源
      最近更新 更多