prevent touchstart when swiping

前端 未结 11 2039
萌比男神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:08

    Quoting from DA.:

    This is a working example:

    var touch_pos;
    $(document).on('touchstart', '.action-feature', function(e) {
      e.preventDefault();
      touch_pos = $(window).scrollTop();
    }).on('click touchend', '.action-feature', function(e) {
      e.preventDefault();
      if(e.type=='touchend' && (Math.abs(touch_pos-$(window).scrollTop())>3)) return;
      alert("only accessed when it's a click or not a swipe");
    });
    

提交回复
热议问题