Javascript equivalent of iOS's 'tap' event, but for android

て烟熏妆下的殇ゞ 提交于 2019-12-22 09:49:09

问题


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
});

回答1:


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>


来源:https://stackoverflow.com/questions/6820863/javascript-equivalent-of-ioss-tap-event-but-for-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!