是否可以检测到视口(viewport)正在被触摸事件拖动?
使用以下代码,我可以获得手指触摸屏幕的位置、启动事件的节点以及拖动到的位置。这解决了其中一个问题,但我真的很想检测用户何时向下拖动页面/窗口/视口(viewport)。
试图更清楚地说明我正在尝试做什么:我想在 iPhone 的 Tweetie 2/Twitter 中模拟刷新 Activity ,但在 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>
最佳答案
在 touchmove 事件中,event.targetTouches[0].pageX 和 .pageY 属性将为您提供触摸坐标的运行指示。你需要在touchstart中存储原始触摸位置,在touchmove中更新当前位置,然后在touchend中,通过计算x轴和y轴之间的差异来判断触摸是否为上、下、左、右开始和结束的位置。 touches 数组的长度会让你知道是单指滑动还是双指捏合。
关于javascript - 用于移动浏览器的 iPhone/Android 滑动检测,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3150749/