本文介绍了单击iPhone上的延迟和抑制输入焦点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iphone上的webkit浏览器在用户进行触摸和javascript获取点击事件之间有300毫秒的延迟。发生这种情况是因为浏览器需要检查用户是否进行了双击。我的应用程序不允许缩放,因此双击对我来说毫无用处。很多人对这个问题都有涉及处理触摸结束事件的点击,然后忽略浏览器生成的点击。但是,似乎无法抑制发送到输入元素的单击。如果您在表单上方打开一个对话框,然后用户点击关闭按钮,当表单消失时,他们的点击将被路由到输入元素,这可能会导致问题。



(仅限iphone)

解决方案

我和我的同事开发了一个名为,用于摆脱Mobile Safari中的点击延迟。它将触摸转换为点击并处理输入选择元素的特殊情况。



就像在身体上实例化一样简单: new FastClick(document.body),然后像往常一样监听点击事件。 / p>

The webkit browser on iphone has a 300ms delay between when a user does a touch and when the javascript gets a click event. This happens because the browser needs to check if a user has done a double tap. My app doesn't allow zooming so a double tap is useless for me. A number of people have proposed solutions to this problem and they usually involve handling the 'click' on the touch end event and then ignoring the click generated by the browser. However, it doesn't seem to be possible to suppress a click that gets sent to an input element. This can cause a problem if you have a dialog that opens above a form then a user hits the close button and their click gets routed to an input element when the form disappears.

Example with jqtouch (for iphone only)

解决方案

My colleagues and I developed an open source library called FastClick for getting rid of the click delay in Mobile Safari. It converts touches to clicks and handles those special cases for input and select elements cleanly.

It's as easy as instantiating it on the body like so: new FastClick(document.body), then listening for click events as usual.

这篇关于单击iPhone上的延迟和抑制输入焦点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-26 16:01