2011-10-24 14 views
34

私はどのように私はjQueryのにこれを翻訳することができ翻訳タッチイベント

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

を使用していますか?私は試しました:

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

アイデア?

+2

ありがとう、比較的新しいサイトです。ちょうど戻って良かった答えを承認しました。 – K2xL

+0

心配はいりません。うれしいことが分かりました:) –

+1

シンプルなjQueryライブラリ:https://github.com/Tundra-Interactive/swipe.jquery.js –

答えて

46

jQueryは、ブラウザの違いを考慮してイベントを修正します。そうすると、いつでもevent.originalEvent(特別なプロパティ小見出しthis pageを参照)で 'ネイティブ'イベントにアクセスすることができます。

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

私は長い時間前に尋ねられたことは知っていますが、具体的な例が役立つと思いました。

+1

"具体的な例"が真剣に有益であるという概念を取ってくれてありがとう。 –