prevent touchstart when swiping

前端 未结 11 2070
萌比男神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 20:57

    I had the same problem, here's a quick solution which works for me

    $(document).on('touchstart', 'button', function(evt){ 
        var oldScrollTop = $(window).scrollTop();
        window.setTimeout( function() {
            var newScrollTop = $(window).scrollTop();
            if (Math.abs(oldScrollTop-newScrollTop)<3) $button.addClass('touchactive');
        }, 200);
    });
    

    basically instead of handling touchstart immediately, wait for some milliseconds (200ms in this example), then check the scroll position, had scrollposition changed, then we need not to handle touchstart.

提交回复
热议问题