简体   繁体   English

在PC浏览器上模拟触摸事件

[英]Simulating touch events on a PC browser

I am developing an HTML application for the iPad. 我正在为iPad开发一个HTML应用程序。 As such it utilizes touch events and webkit-CSS animations. 因此,它利用触摸事件和webkit-CSS动画。

Up until now I have used chrome as my debugging environment because of it's awesome developer mode. 到目前为止,我已经使用chrome作为我的调试环境,因为它是非常棒的开发人员模式。

What I would like is to be able to debug my Html/JavaScript using Google-Chrome's debugger on my PC while simulating touch events with my mouse. 我想要的是能够在我的PC上使用Google-Chrome的调试器调试我的Html / JavaScript,同时使用鼠标模拟触摸事件。

My site does not have any multi-touch events and no mouse events (no mouse on iPad). 我的网站没有任何多点触控事件,也没有鼠标事件(iPad上没有鼠标)。

I am not actually interested in seeing the applications layout, but more in debugging its behavior. 我实际上并不想看到应用程序布局,但更多的是调试它的行为。

Is there some plugin to get mouse events translated into touch events on a desktop browser? 是否有一些插件可以将鼠标事件转换为桌面浏览器上的触摸事件?

As of April 13th 2012 截至2012年4月13日

In Google Chrome developer and canary builds there is now a checkbox for "Emulate touch events" 在Google Chrome开发人员和canary版本中,现在有一个“模拟触摸事件”复选框

You can find it by opening the F12 developer tools and clicking on the gear at the bottom right of the screen. 您可以通过打开F12开发人员工具并单击屏幕右下方的齿轮来找到它。

在Chrome v22 Mac OS X上

For now (Chrome ver.36.0.1985.125) you can find it here: F12 => Esc => Emulation. 现在(Chrome ver.36.0.1985.125)你可以在这里找到它:F12 => Esc => Emulation。 安慰

The desktop browser can simulate touch events by importing additional JS + CSS. 桌面浏览器可以通过导入其他JS + CSS来模拟触摸事件。 Take a look at: 看一眼:

  1. addTouch addTouch
  2. Phantom Limb 幻影肢体

另一种在桌面浏览器上模拟多点触控的方法是Hammer.jsTouch Emulator

We use this script: http://code.google.com/p/jquery-ui-for-ipad-and-iphone/ It will allow all mouse events in your application to be triggered by touch events instead. 我们使用此脚本: http//code.google.com/p/jquery-ui-for-ipad-and-iphone/它将允许触摸事件触发应用程序中的所有鼠标事件。 So, since we already had a web application that used right-clicking, drag-n-drop etc. it allowed us to perform all of the same functionality with touch. 因此,由于我们已经有一个使用右键单击,拖放等功能的Web应用程序,因此它允许我们通过触摸执行所有相同的功能。

I know it's almost the reverse of the simulation you were looking for (you will have to script your application to primarily be used by a mouse) but I hope it helps anyway. 我知道这几乎与您正在寻找的模拟相反(您必须将您的应用程序编写为主要由鼠标使用),但我希望它无论如何都有帮助。

I came across this little library based on the JQ UI lib. 我基于JQ UI lib遇到了这个小库。 Pretty nifty: 漂亮俏皮:

http://touchpunch.furf.com/ http://touchpunch.furf.com/

If you're targeting Webkit specifically (iPad and all), you can rely on normal event handler code (add/removeEventListener). 如果您专门针对Webkit(iPad和所有),则可以依赖正常的事件处理程序代码(add / removeEventListener)。 With that in mind, you probably need to just branch on a few events - eg, 'ontouchstart' becomes 'onclick' based on the environment. 考虑到这一点,您可能只需要分支几个事件 - 例如,'ontouchstart'根据环境变为'onclick'。

Offhand I don't know of any libraries providing this level of branching, though. 但是,我并不知道任何提供此级别分支的库。 Pretty easy to do yourself. 自己很容易做到。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM