Javascript equivalent of iOS's 'tap' event, but for 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 = (u开发者_StackOverflow社区serAgent.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
});
Tap event working on my android 4.1 Samsung pocket phone
$(function() {
$('#tapme').bind('tap', function() {
$(this).parent().after('<li>tapped!</li>')
});
});
it works only when I include it inside
$(function() {
--- bind here --
});
and also for android, add this line
var jQT = new $.jQTouch({
useFastTouch: false
});
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>
with zepto
<script src="zepto.min.js" type="text/javascript" ></script>
<script src="jqt.min.js" type="text/javascript" ></script>
精彩评论