【问题标题】:jquery mobile - detecting touches array on swipe eventjquery mobile - 在滑动事件上检测触摸数组
【发布时间】:2017-01-06 20:54:06
【问题描述】:

我正在使用 jquery mobile 来检测触摸屏上的滑动。我想收听swipe 事件,但只有在超过一根手指触摸屏幕时才做某事。我知道对于正常的触摸事件,这可以通过事件中的touches 数组检测到,但是当我在swipe 被触发后在事件中检查时,这似乎不存在。谁能指出我在触发swipe 事件后如何访问touches 数组的正确方向?

【问题讨论】:

  • 你尝试了什么?

标签: jquery jquery-mobile swipe touch-event


【解决方案1】:

我发现我应该覆盖的不是 jquery mobile,而是我使用的幻灯片插件 (jquery cycle2)。这是我想出的代码:

window.global_touches = null;

$('.page').on({
    touchstart: function(e) {
      e.preventDefault();
      window.global_touches = e.originalEvent.touches;
    },
    touchmove: function(e) {
      window.global_touches = e.originalEvent.touches;
    },
    touchend: function(e) {
      window.global_touches = e.originalEvent.touches;
    },
    touchcancel: function(e) {
      window.global_touches = e.originalEvent.touches;
      clearHighlight();
    }
});

$('.inner-slideshow').on('cycle-bootstrap', function(e, optionHash, API) {
    API.origAdvanceSlide = API.advanceSlide;
    API.advanceSlide = function(numberOfPositions) {
        if (window.global_touches && window.global_touches.length >= 2) {
           API.origAdvanceSlide.call(API, numberOfPositions);
        }
    };
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-11-23
    • 1970-01-01
    • 1970-01-01
    • 2013-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-25
    相关资源
    最近更新 更多