问题描述
我正在使用jqtouch制作触控优化网站。对于iOS,我将tap绑定到单击侦听器,但这不会在Android中注册。我尝试使用touchend,它可以工作,但它会覆盖任何类型的拖动(当用户尝试做的每一个都是滚动时单击项目)。我会为Android绑定什么?这是我的代码:
I am using jqtouch to make a touch-optimized site. For iOS, I bind "tap" to the click listener, but this doesn't register in Android. I tried using touchend, which works, but it then overrides any sort of dragging (click on items when all a user is trying to do is scroll). What would I bind it to for Android? Here's my code:
var userAgent = navigator.userAgent.toLowerCase();
var isiPhone = (userAgent.indexOf('iphone') != -1 || userAgent.indexOf('ipad') != -1 || userAgent.indexOf('ipod') != -1) ? true : false;
var isAndroid = (userAgent.indexOf('android') != -1) ? true : false;
clickEvent = isiPhone ? 'tap' : 'click';
//NEED TO SET THIS UP FOR ANDROID, BUT 'TAP' DOESN'T WORK
$('.work_img').bind(clickEvent, function(event){
//DO STUFF ON CLICK / TAP
});
推荐答案
点击活动在我的Android 4.1三星手机上工作
Tap event working on my android 4.1 Samsung pocket phone
$(function() {
$('#tapme').bind('tap', function() {
$(this).parent().after('<li>tapped!</li>')
});
});
仅当我将其包含在内时
$(function() {
--- bind here --
});
以及android,添加此行
and also for android, add this line
var jQT = new $.jQTouch({
useFastTouch: false
});
当你使用jquery时确保包含这三个(订单事宜!!)
when u use jquery make sure these three are included (order matters!!)
<script src="jquery-1.7.min.js" type="text/javascript"></script>
<script src="jqt.min.js" type="text/javascript"></script>
<script src="jqtouch-jquery.min.js" type="text/javascript"></script>
使用zepto
<script src="zepto.min.js" type="text/javascript" ></script>
<script src="jqt.min.js" type="text/javascript" ></script>
这篇关于Javascript相当于iOS的'tap'事件,但是对于android的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!