Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Translating touch events from Javascript to jQuery

I am using

window.addEventListener("touchstart", function(ev){
    console.log(ev.touches); // good
});

How can I translate this to jQuery? I've tried:

$(window).bind("touchstart",function(ev){
    console.log(ev.touches); // says ev.touches is undefined
}

Any ideas?

like image 345
K2xL Avatar asked Oct 24 '11 16:10

K2xL


2 Answers

jQuery 'fixes up' events to account for browser differences. When it does so, you can always access the 'native' event with event.originalEvent (see the Special Properties subheading on this page).

like image 138
Dan Davies Brackett Avatar answered Nov 15 '22 22:11

Dan Davies Brackett


$(window).on("touchstart", function(ev) {
    var e = ev.originalEvent;
    console.log(e.touches);
});

I know it been asked a long time ago, but I thought a concrete example might help.

like image 45
Simon Arnold Avatar answered Nov 15 '22 23:11

Simon Arnold