【问题标题】:iPhone/Android swipe detection for mobile browser用于移动浏览器的 iPhone/Android 滑动检测
【发布时间】:2010-06-30 15:27:54
【问题描述】:

是否可以检测到视口被触摸事件拖动?

使用以下代码,我可以获得手指触摸屏幕的位置、启动事件的节点以及拖动到的位置。这解决了其中一个问题,但我真的很想检测用户何时向下拖动页面/窗口/视口。

为了更清楚地了解我想要做什么:我想在 Tweetie 2/Twitter for iPhone 但在 HTML5 和 JavaScript 中模拟刷新活动。

<script> 
window.ontouchmove = function(e){
  if(e.touches.length == 1){ // Only deal with one finger
    var touch = e.touches[0]; // Get the information for finger #1
    var node = touch.target; // Find the node the drag started from
    $("p:last").html(
        "clienty: " + touch.clientY + "<br/>" +
        "screenY: " + touch.screenY + "<br/>" +
        "pageY: "   + touch.pageY
        );
  }
}
</script> 

【问题讨论】:

    标签: javascript iphone android html swipe


    【解决方案1】:

    在 touchmove 事件中,event.targetTouches[0].pageX 和 .pageY 属性将为您提供触摸坐标的运行指示。您需要将原始触摸位置存储在 touchstart 中,在 touchmove 中更新当前位置,然后在 touchend 中,通过计算 x 和 y 轴之间的差异来确定触摸是否向上、向下、向左、向右起点和终点位置。 touches 数组的长度会让您知道是单指轻扫还是两指捏合。

    【讨论】:

      【解决方案2】:

      您可能想查看Sencha Touch。它是一个支持这些事件的移动框架,因此您不必推出自己的支持。

      【讨论】:

      • sencha aka ExtJS 带有如此多的 HTML/div clobber...鉴于您的出发点,我宁愿寻找一个 jQuery 插件...
      猜你喜欢
      • 2011-10-01
      • 2019-10-09
      • 2011-04-18
      • 2015-09-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多