Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get Android to respond to touch drags?

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!

like image 444
Tom Murray Avatar asked Jan 28 '26 05:01

Tom Murray


1 Answers

Please use:

event.touches[0].pageY

instead of:

event.pageY

it will work.

like image 161
Abu Saad Papa Avatar answered Jan 30 '26 20:01

Abu Saad Papa



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!