2

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

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

为了更清楚地了解我想要做什么:我想在 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> 
4

2 回答 2

6

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

于 2010-08-11T07:29:56.380 回答
2

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

于 2010-06-30T15:44:11.050 回答