jquery如何为移动设备实现触摸事件? [英] How would jquery implement touch events for mobile devices?

查看:123
本文介绍了jquery如何为移动设备实现触摸事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这更像是一个概念性问题。在阅读了关于Jquery Mobile之后,它让我思考如何使用普通的javascript实现触摸事件,如tap或rub。由于Jquery Mobile是基于javascript构建的,这是否意味着Jquery团队能够将自定义事件添加到vanilla javascript中,例如 ontap ondrag

This is more of a conceptual question. After reading about Jquery Mobile, it got me thinking about how one would implement touch events like "tap" or "rub" using plain javascript. Since Jquery Mobile is built on javascript, does that mean the Jquery team is able to add custom events to vanilla javascript like ontap or ondrag?

这总结了我的思考过程:

This sums up my thought process:


  1. Jquery是基于vanilla的基本功能构建Javascript

  2. vanilla的基本功能Javascript不支持触摸事件;因此,Jquery不支持触摸事件

  3. 结论:为了让Jquery支持触摸事件,vanilla Javascript必须包含触摸事件?


推荐答案

某些移动浏览器能够触发与触摸屏交互相关的事件。移动Safari(不知道其他移动浏览器,但事情不应该改变太多)例如有一些自定义事件,如 touchstart touchmove touchend

Some mobile browsers are able to fire events related to the interaction with a touch screen. Mobile Safari (don't know about other mobile browser but things shouldn't change much) for example has some custom events like touchstart, touchmove or touchend

http://developer.apple.com/library/IOs/#documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/ HandlingEvents.html

这就是jQuery mobile和其他库能够处理这类事件的方式。
如果你想深入了解这个事件之一的简单真实世界实现,你可以看一下这个库的源代码,它处理'swipe'事件。

That's how jQuery mobile and other libraries are able to handle this kind of events. If you want to dig deeper into a simple "real-world" implementation of one of this event you can have a look at the source code of this library, which handles the 'swipe' event.

https://github.com /cubiq/SwipeView/blob/master/src/swipeview.js

这篇关于jquery如何为移动设备实现触摸事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆