利用点击的jQuery Mobile的自来水代替 [英] Using jquery mobile tap instead of click

查看:148
本文介绍了利用点击的jQuery Mobile的自来水代替的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在需要两个移动设备以及非移动装置上运行的Web应用程序。在我的应用我有几个图标,用户可以以使用的WebSockets将消息发送到服务器,请单击。

I'm making a web application that needs to run on both mobile devices as well as non-mobile devices. In my application I have several icons the user can click in order to send a message to a server using websockets.

我的code看起来是这样的:

My code looks something like:

$('.button-container').on('tap', '.sender', function() {
    socket.send('Message');
});

使用,而不是'点击''水龙头'是为了提供对iPad的(和其他移动设备)的支持,但由于这似乎是有点一个黑客,我有一些顾虑。

Using 'tap' instead of 'click' is done to provide support for the iPad (and other mobile devices), but as this seems like somewhat of a hack, I have a few concerns.

水龙头,似乎在我的测试浏览器,Safari浏览器7,Chrome浏览器34和Firefox 26,(所有非移动),但如何对其他非移动浏览器支持?

'tap' seems to work on my test browsers, Safari 7, Chrome 34, and Firefox 26, (all non-mobile) but how is support for other non-mobile browsers?

另外有没有使用'水龙头'在任何已知的问题,然后单击对于非移动浏览器?

Also are there any known issues using 'tap' over 'click' for non-mobile browsers?

推荐答案

jQuery Mobile的特别活动,即点击 taphold V单击 ...等,都是原本的触摸小鼠的转换为特殊活动事件。

jQuery Mobile special events i.e. tap, taphold, vclick...etc, are originally touch and mouse events converted into special events.

例如,点击 V单击要么是 touchstart / touchend 鼠标按下 / 鼠标松开

For example, tap and vclick are either touchstart/touchend or mousedown/mouseup.

在加载jQuery Mobile的,它会检查,如果浏览器支持的触摸的,因此事件被转换成的小鼠的事件或触摸的事件。

On loading jQuery Mobile, it checks if browser supports touch and accordingly events are converted into mouse events or touch events.

您可以根据浏览器的支持触摸事件之间切换。对于非触摸浏览器,使用点击,并支持那些触摸,使用点击

You can alternate between events depending on browser's touch support. For non-touch browsers, use click and the ones that support touch, use tap.

在启动时,请检查 $。support.touch ,它将返回的真正的(水龙头)或的(点击)。

On start-up, check $.support.touch, it will return true (tap) or false (click).

var custom_event = $.support.touch ? "tap" : "click";

$(document).on(custom_event, "element", function () {
  /* code */
});

测试下面的演示桌面和移动上。

Test the below demo on your desktop and mobile.

演示

Demo

这篇关于利用点击的jQuery Mobile的自来水代替的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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