手持上click事宜的响应速度远远不如touchstart。然则仅仅写touch事宜很不轻易web端开辟测试,所以下边的推断很有必要。
var isSupportTouch = "ontouchend" in document ? true : false, touchEv = isSupportTouch ? 'touchstart' : 'mousedown', touchEndEv = isSupportTouch ? "touchend" : 'mouseup';
别的:
var isSupportTouch = "ontouchend" in document ? true : false, touchEv = isSupportTouch ? 'touchstart' : 'click';
用起来就很轻易啦
$obj.on(touchEv,function(){ \\事宜 });
另有一种写法:
isTouch = !!navigator.userAgent.match(/AppleWebKit.*Mobile.*/);,
eStart = isTouch ? 'touchstart' : 'mousedown',
eMove = isTouch ? 'touchmove' : 'mousemove',
eEnd = isTouch ? 'touchend' : 'mouseup';