平板电脑和触摸屏手机的jQuery单击事件

平板电脑和触摸屏手机的jQuery单击事件

本文介绍了平板电脑和触摸屏手机的jQuery单击事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我刚开始从事移动/平板电脑平台的Web开发工作.我对在浏览器环境中进行开发非常有信心.

Ok, I am fairly new to web development for mobile/tablet platforms. I am pretty confident though in developing for a browser environment.

我的问题是我没有任何平板电脑(我很穷,所以必须盲目飞行),所以我很难进行测试.对于点击事件无法正常运行,我也很着急.

My problem is that I don't own any tablet (I am poor so have to fly blind) so it's hard for me to do testing. I'm also quite anxious about the click events not working properly.

关于点击事件和平板电脑/智能手机的最佳做法是否达成共识?

Is there any consensus on best practice for click events and tablets/smartphones?

注意:我不是在开发仅限移动设备的网站-该网站可以改变移动设备的形状.

Note: I am not developing a mobile only site - the site transforms shape for mobile.

推荐答案

移动浏览器仍会响应点击事件,尽管会带来延迟(通常为300毫秒左右).如果您希望获得更快的响应速度,可以尝试检测您是否在移动平台上,并使用 touchstart touchend 事件.我发现 touchend 通常是更好的体验,主要是因为 touchstart 触发时,用户的手仍在阻碍之中.

Mobile browsers will still respond to click events, though they will introduce a delay (usually around 300 ms). If you want a more responsive experience, you can try to detect if you are on a mobile platform and use either touchstart or touchend events. I find touchend is usually a better experience, mainly because the user's hand is still in the way when touchstart fires.

类似这样的东西:

$(element).on(isMobile?'touchend':'click',function(e){...});

或者您可以使用 hammer.js ,它既适用于台式机,也适用于移动设备

Or you can use hammer.js, which will work for both desktop and mobile.

对于测试,您可以阅读以下有关Stackoverflow问题的答案:在PC浏览器上模拟触摸事件.

As for testing, you can read through the answers to this Stackoverflow question: Simulating touch events on a PC browser.

这篇关于平板电脑和触摸屏手机的jQuery单击事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 09:25