2011-10-24 47 views
34

我使用翻译触摸事件从Javascript jQuery的

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

如何翻译这jQuery的?我试过了:

$(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

感谢您认真对待“具体示例”这一概念。 –