views:

200

answers:

2

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);
});         
A: 

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);
michael
'e.touches' is not an object
coure06
I've updated my code. Try that. If it works then you can go from there.
michael
+1  A: 

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://www.the-xavi.com/articles/trouble-with-touch-events-jquery

Xavi
Working on iphone but not working on iPad. Any idea?
coure06
hmm, just tried on my ipad... everything seemed to work as expected. Are you seeing any errors? Also have you tried checking `e.originalEvent.changedTouches[0]`?
Xavi