prevent touchstart when swiping

前端 未结 11 2075
萌比男神i
萌比男神i 2020-11-30 20:09

I have a scrollable list on a mobile device. They want people to be able to scroll the list via swiping, and also select a row by tapping.

The catch is combining th

11条回答
  •  情书的邮戳
    2020-11-30 21:05

    if you want to do this for multiple elements and also need mouse and pointer events:

    var elems = $('YOURMULTISELECTOR'); // selector for multiple elements
    elems.unbind('mousdown pointerdown touchstart touchmove mouseup pointerup touchend');
    var elem = null;
    elems.on('mousdown pointerdown touchstart', function (e) {
        elem = yourSingleSelector(e);
    }).on('touchmove', function (e) {
        elem = null;                
    }).on('mouseup pointerup touchend', function (e) { 
        if (elem == yourSingleSelector(e)) {                    
            // do something
        }
    });
    

提交回复
热议问题