admin管理员组文章数量:1279118
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.
My code looks something like:
$('.button-container').on('tap', '.sender', function() {
socket.send('Message');
});
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.
'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?
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.
My code looks something like:
$('.button-container').on('tap', '.sender', function() {
socket.send('Message');
});
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.
'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?
Share Improve this question asked Jan 7, 2014 at 23:43 The BearThe Bear 2333 silver badges6 bronze badges1 Answer
Reset to default 10jQuery Mobile special events i.e. tap
, taphold
, vclick
...etc, are originally touch and mouse events converted into special events.
For example, tap
and vclick
are either touchstart
/touchend
or mousedown
/mouseup
.
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
.
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
本文标签: javascriptUsing jquery mobile tap instead of clickStack Overflow
版权声明:本文标题:javascript - Using jquery mobile tap instead of click - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741255153a2366527.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论