如何在iPad的Safari中使用jQuery识别触摸事件?是否有可能? [英] How can I recognize touch events using jQuery in Safari for iPad? Is it possible?

查看:104
本文介绍了如何在iPad的Safari中使用jQuery识别触摸事件?是否有可能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用jQuery在iPad的Safari浏览器上识别触摸事件?

Is it possible to recognize touch events on the iPad's Safari browser using jQuery?

我在Web应用程序中使用了mouseOver和mouseOut事件. iPad的Safari浏览器是否有类似事件,因为没有mouseOut和mouseMove之类的事件?

I used mouseOver and mouseOut events in a web application. Are there any similar events for the iPad's Safari browser since there are no events like mouseOut and mouseMove?

推荐答案

Core jQuery的触摸事件没有什么特别之处,但是您可以使用以下事件轻松构建自己的事件

Core jQuery doesn't have anything special for touch events, but you can easily build your own using the following events

  • touchstart
  • 触摸移动
  • touchend
  • touchcancel

例如touchmove

document.addEventListener('touchmove', function(e) {
    e.preventDefault();
    var touch = e.touches[0];
    alert(touch.pageX + " - " + touch.pageY);
}, false);

这在大多数基于基于WebKit 的浏览器(包括Android)中有效.

This works in most WebKit based browsers (incl. Android).

这里有一些很好的文档.

这篇关于如何在iPad的Safari中使用jQuery识别触摸事件?是否有可能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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