我如何获得Android的响应触摸一拖再拖?如何获得、一拖、Android

2023-09-06 17:18:34 作者:旧时光的帅气少年

我创建一个web应用程序拥有的div溢出:滚动造型。由于Android的浏览器不支持此,我需要使用触摸和拖​​拽用我自己的自定义功能。

I'm creating a web app featuring divs with overflow: scroll styling. Since the Android browser doesn't support this, I need to use touches and drags with my own custom function.

$([element]).
.bind('touchmove', function(event) {
    event.preventDefault();
    // Move elements around as page scrolls, using event.pageY
})
.bind('touchstart', function(event) {
    event.preventDefault();
    // Do stuff to set up scrolling event.
}

这工作正常在iOS设备上。但是,在Android中,它没有。

This works fine on iOS devices. However, in Android, it does not.

使用的console.log,我发现event.pageY总是被设置为零(iOS中它会告诉你,你的接触是相对于页面的其余部分)。我也得到了以下晦涩的消息:

With console.log, I found out that event.pageY is always set to zero (in iOS it tells you where your touch is in relation to the rest of the page). I also get the following cryptic message:

W/webview (21798): Miss a drag as we are waiting for WebCore's response for touch down.

数据对这个已经微乎其微,但它似乎是Android不实际注册触摸事件,直至取消触摸的情况。我不相信它,因为正常的页面滚动的罚款。我只是不知道热,以使其接受而不是忽略触摸的Y值pageY的真正价值。

Data on this has been minimal, but it seems to be the case that Android doesn't actually register a touch event until you un-touch. I don't believe it, since normal pages scroll fine. I just don't know hot to get it to recognize the real value of pageY, instead of ignoring the Y-value of the touch.

为寻找谢谢!

推荐答案

请使用:

event.touches [0] .pageY

来代替:

event.pageY

它会工作。

 
精彩推荐
图片推荐