Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iphone's safari touchmove event not working

i am using jquery and touchmove event but the code is not showing anything in #info

$('#movieShow').bind('touchmove',function(e){                   
    e.preventDefault();                 
    $('#info').text(e.touches[0].pageX);
});         
like image 969
coure2011 Avatar asked Aug 20 '10 14:08

coure2011


2 Answers

Try using e.originalEvent.touches:

$('#movieShow').bind('touchmove',function(e){
    e.preventDefault();

    var touch = e.originalEvent.touches[0] || e.originalEvent.changedTouches[0];
    console.log(touch.pageX);
});

I ran into a similar problem when I was playing around with touch events and jquery: http://xavi.co/articles/trouble-with-touch-events-jquery

like image 127
Xavi Avatar answered Nov 11 '22 08:11

Xavi


It might be as simple as a mis-named DIV id ('#info') but can't tell without seeing everything.

Try this, and see if you still get no output:

$('#movieShow').bind('touchmove',function(e){                   
    e.preventDefault();                 
    console.log(e.touches[0].pageX);
});

(You'll need to turn on Debug Console in MobileSafari)

UPDATE

So, from your comment you get an error: 'e.touches' is not an object

In that case try this (not jQuery specific):

document.addEventListener('touchmove', function(e) { e.preventDefault(); }, false);
document.getElementById('movieShow').addEventListener('touchmove',  function(e){
  console.log(e.touches[0].pageX);
},  false);
like image 1
donohoe Avatar answered Nov 11 '22 08:11

donohoe