【问题标题】:How to make work jquery "swipe" with scroll on iPad?如何在 iPad 上通过滚动使工作 jquery “滑动”?
【发布时间】:2015-12-18 08:48:23
【问题描述】:

我有两个 div,彼此相邻。除了click 事件,我还添加了swiperightswipeleft 来做一些事情。但是当我添加这些 swipe 事件时,滚动在 iPad 上不再起作用。在 PC 上没有问题!

有没有其他方法可以让它们在 iPad(触摸屏设备)上相互兼容?

谢谢!

【问题讨论】:

  • 你能展示一下你到目前为止所做的尝试吗?

标签: javascript jquery ios ipad


【解决方案1】:

找到了解决方案:

http://stephband.info/jquery.event.swipe/

Swipe 事件是基于移动事件 (stephband.info/jquery.event.move) 构建的薄包装器。默认情况下,移动事件会覆盖原生滚动,因为它们假定您想要移动某些内容而不是滚动窗口。要重新启用滚动,请在 movestart 处理程序中调用 e.preventDefault()。

在上面的示例中,我们希望能够向左和向右滑动,但可以上下滚动。在 movestart 处理程序中,计算手指移动的方向,如果发现向上或向下移动,则阻止该事件::

jQuery('.mydiv')
.on('movestart', function(e) {
  // If the movestart is heading off in an upwards or downwards
  // direction, prevent it so that the browser scrolls normally.
  if ((e.distX > e.distY && e.distX < -e.distY) ||
      (e.distX < e.distY && e.distX > -e.distY)) {
    e.preventDefault();
  }
});

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多