最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How do I get Android to respond to touch drags? - Stack Overflow

programmeradmin1浏览0评论

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.
}

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

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.

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.

Thanks for looking!

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.
}

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

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.

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.

Thanks for looking!

Share Improve this question asked Oct 7, 2011 at 0:13 Tom MurrayTom Murray 811 silver badge3 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 6

Please use:

event.touches[0].pageY

instead of:

event.pageY

it will work.

发布评论

评论列表(0)

  1. 暂无评论