Detect touch events in Chrome on Windows 8 with touchscreen

三世轮回 提交于 2019-12-08 01:57:21

问题


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.Check is touch device:

base.isTouch = ("ontouchstart" in document.documentElement);

2.Get proper events

if(base.isTouch === true){
    //use touch events:
    "touchstart.owl",
    "touchmove.owl",
    "touchend.owl"
} else {
    //usemouse events
    "mousedown.owl",
    "mousemove.owl",
    "mouseup.owl"
}

3.Check touch events:

if(base.isTouch === true){
    x = event.touches[0].pageX
    y = event.touches[0].pageY
} else {
    x = event.pageX
    y = event.pageY
}

link to real code

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);

Which is OK but then i have a problem with event.touches[0].pageX

link to plugin landing page

Thanks!

Problem solved

To get mouse and touch events working together on windows 8 chrome with touchscreen i had to:

1.add two events on one element "touchstart.owl mousedown.owl"

2.check "event.touches":

if(event.touches){
    x = event.touches[0].pageX
    y = event.touches[0].pageY
} else {
    x = event.pageX
    y = event.pageY
}

回答1:


To get mouse and touch events working together on windows 8 chrome with touchscreen i had to:

1.add two events on one element "touchstart.owl mousedown.owl"

2.check "event.touches":

if(event.touches){
    x = event.touches[0].pageX
    y = event.touches[0].pageY
} else {
    x = event.pageX
    y = event.pageY
}



回答2:


The simplest solution is to include Touch Punch plug-in http://touchpunch.furf.com/

I did it for my project and it works well - U can test it, here is my project: http://englishtotheworld.com/



来源:https://stackoverflow.com/questions/18761078/detect-touch-events-in-chrome-on-windows-8-with-touchscreen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!