H5 sliding does not trigger click event

Time:2022-5-13
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)
        }
    });
}

Recommended Today

Drawing system of Android Q skia

Lifelong learning with you, this is Android programmer Classic good articles are recommended. By reading this article, you will gain the following knowledge points: 1、 Drawing mechanism of view2、 Hwui drawing architecture3、 Render device4、 ImageView drawing5、 Geometric treatment during drawing skmatrix The biggest change in Android Q rendering system is to add skia’s part. Before […]