为什么/何时必须点按两次以触发点击iOS [英] Why/when do I have to tap twice to trigger click on iOS

查看:433
本文介绍了为什么/何时必须点按两次以触发点击iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧我觉得我疯了......

Ok I feel like I'm crazy...

我正在看iOs 6.0上的Mobile Safari。我似乎无法确定任何押韵或理由,因为点击一个元素会触发点击。在许多情况下,似乎我需要点击一次才能触发悬停,然后再次触发点击。

I'm looking at Mobile Safari on iOs 6.0. I can't seem to establish any rhyme or reason as to when tapping on an element will trigger click. In many cases, it seems I need to tap once to trigger a hover and then again to trigger a click.

Mobile Safari规范说:......由一个人产生的事件流 - 手指和双指手势是有条件的,具体取决于所选元素是否可点击或可滚动...可点击元素是链接,表单元素,图像映射区域或具有mousemove,mousedown,mouseup或onclick的任何其他元素处理程序......由于存在这些差异,您可能需要将一些元素更改为可单击元素...

The Mobile Safari spec says : "... The flow of events generated by one-finger and two-finger gestures are conditional depending on whether or not the selected element is clickable or scrollable... A clickable element is a link, form element, image map area, or any other element with mousemove, mousedown, mouseup, or onclick handlers... Because of these differences, you might need to change some of your elements to clickable elements..."

它继续建议开发人员。 ..添加一个虚拟onclick处理程序,onclick =void(0),以便iOS上的Safari将span元素识别为可点击元素。

It goes on to suggest that the developer "...Add a dummy onclick handler, onclick = "void(0)", so that Safari on iOS recognizes the span element as a clickable element."

然而,我的测试表明这些陈述是错误的。

However, my testing has shown these statements to be false.

JsFiddle: http://jsfiddle.net/6Ymcy/1/

JsFiddle : http://jsfiddle.net/6Ymcy/1/

html

<div id="plain-div" onclick="void(0)">Plain Div</div>

js

document.getElementById('plain-div').addEventListener('click', function() {
   alert('click'); 
});

尝试点击iPad上的元素。 什么都不会发生

Try tapping the element on an iPad. Nothing Happens

但是我离题了。对我来说重要的是找出以下问题:

But I digress. What is important to me is to find out the following question:

确定点击某个元素时确定触发点击事件的标准是什么在第一次点按?而不是在第一次点按时触发'悬停'事件,在第二次点击时触发'点击'事件。

Exactly what are the criteria that determine when clicking on an element will fire a 'click' event on the first tap? As opposed to firing a 'hover' event on the first tap and a 'click' event on the second tap.

在我的测试,锚元素是我可以在第一次点击时触发点击的唯一元素,然后,只是偶尔和不一致。

In my testing, anchor elements are the only elements that I can get to fire a click on the first tap, and then, only occasionally and inconsistently.

这是我开始感觉到的地方疯。我在网上广泛搜索,发现这个问题几乎没有。只有我吗?!有没有人知道哪里有关于双击标准和/或处理这些限制的方法的讨论?

Here's where I start to feel crazy. I searched the internet far and wide and found next to nothing about this issue. Is it just me?! Does anybody know where there's been any discussion about the criteria for two-taps and or an approach to dealing with these limitations?

我很乐意回答问题/要求。

I'm happy to respond to questions/requests.

谢谢!

推荐答案

我遇到了同样的问题。最简单的解决方案是不要在iOS(或任何支持触摸的目标平台)上绑定 mouseenter 事件。如果未绑定,则不会触发悬停事件,并在第一次点击时触发点击。

I had this same issue. The simplest solution is not to bind the 'mouseenter' event on iOS (or any touch enabled target platform). If that is not bound the hover event won't get triggered and click is triggered on the first tap.

这篇关于为什么/何时必须点按两次以触发点击iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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