乐趣区

关于javascript:h5滑动不触发点击事件

function tap(el,fn){var startPoint = {};
    el.addEventListener('touchstart', function(e) {
        startPoint = {x: e.changedTouches[0].pageX,
            y: e.changedTouches[0].pageY
        };
    });
    el.addEventListener('touchend', function(e) {
        var nowPoint = {x: e.changedTouches[0].pageX,
            y: e.changedTouches[0].pageY
        };
        if(Math.abs(nowPoint.x - startPoint.x) < 5
            &&Math.abs(nowPoint.y - startPoint.y) < 5) {fn&&fn.call(el,e)
        }
    });
}
退出移动版