手持装备响应速度优化之-click和touch

手持上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';
    原文作者:dada86
    原文地址: https://segmentfault.com/a/1190000002483799
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞