使用触摸屏在Windows 8上的Chrome中检测触摸事件 [英] Detect touch events in Chrome on Windows 8 with touchscreen
问题描述
我构建了一个对触摸/鼠标友好的jQuery插件.它可以在手机(iOS,Android ...)和台式机浏览器上使用.但是我在带触摸屏的笔记本电脑上安装Windows 8 Chrome时遇到了一些问题.不幸的是,我没有这样的设备,无法进行任何测试.IE10也可以正常工作.
I built a touch/mouse friendly jQuery plugin. It works on phones(ios, android...) and desktops browsers. But i have some issues with Windows 8 Chrome installed on laptop with touch screen. Unfortunately i dont have such a device and cant do any tests.Also IE10 works fine.
让我向您解释我的内在(非常简化的代码):
Let me explain you what i have inside(very simplified code):
1.检查是否为触摸设备:
1.Check is touch device:
base.isTouch = ("ontouchstart" in document.documentElement);
2.获取适当的事件
if(base.isTouch === true){
//use touch events:
"touchstart.owl",
"touchmove.owl",
"touchend.owl"
} else {
//usemouse events
"mousedown.owl",
"mousemove.owl",
"mouseup.owl"
}
3.检查触摸事件:
if(base.isTouch === true){
x = event.touches[0].pageX
y = event.touches[0].pageY
} else {
x = event.pageX
y = event.pageY
}
我认为chrome的问题是检测我的触摸事件,但改用鼠标事件并将其转换为触摸.
I think problem with chrome is that detect my touch events but use mouse events instead and translate them to touch.
我可以一起添加鼠标和触摸事件:
I can add mouse and touch events together:
$('elem').on('mousedown.owl touchstart.owl',func);
哪个还可以,但是我在使用event.touches [0] .pageX
Which is OK but then i have a problem with event.touches[0].pageX
谢谢!
问题已解决
要使鼠标和触摸事件在具有触摸屏的Windows 8 chrome上协同工作,我必须:
To get mouse and touch events working together on windows 8 chrome with touchscreen i had to:
1.在一个元素"touchstart.owl mousedown.owl"上添加两个事件
1.add two events on one element "touchstart.owl mousedown.owl"
2.选中"event.touches":
2.check "event.touches":
if(event.touches){
x = event.touches[0].pageX
y = event.touches[0].pageY
} else {
x = event.pageX
y = event.pageY
}
推荐答案
要使鼠标和触摸事件在带触摸屏的Windows 8 chrome上协同工作,我必须:
To get mouse and touch events working together on windows 8 chrome with touchscreen i had to:
1.在一个元素"touchstart.owl mousedown.owl"上添加两个事件
1.add two events on one element "touchstart.owl mousedown.owl"
2.选中"event.touches":
2.check "event.touches":
if(event.touches){
x = event.touches[0].pageX
y = event.touches[0].pageY
} else {
x = event.pageX
y = event.pageY
}
这篇关于使用触摸屏在Windows 8上的Chrome中检测触摸事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!