2

完整错误:

Ignored attempt to cancel a touchmove event with cancelable=false, for example because scrolling is in progress and cannot be interrupted.
preventDefault  @   jquery-2.2.4.min.js:3
f               @   jquery.ui.touch-punch.min.js:14
b._touchMove    @   jquery.ui.touch-punch.min.js:26
f               @   jquery-2.2.4.min.js:2
dispatch        @   jquery-2.2.4.min.js:3
r.handle        @   jquery-2.2.4.min.js:3

我正在使用touchpunch,这可能会使问题复杂化?正如大多数针对此错误的解决方案所建议的那样,我已尝试添加cancel: false到可拖动选项。它没有帮助。

这被不断地拖着,30-80次。

这是所有与拖动相关的代码:

var t;
$(document).on('touchstart','.menu-item', function (event) {
    selectItem(this);
    var self = this;
    if ($(self).hasClass('draggable')) return;
    t = setTimeout(function () {
        $(self).draggable({
            revert: 'invalid',
            helper: 'clone',
            opacity: .75,
            cancel: false,
            appendTo: 'body',
            cursorAt: {
                left: 100,
                top: 100
            },
            start: function(e, ui)
            {
                $(ui.helper).addClass("ui-draggable-helper");
                $('.menu-container').addClass('stop-scrolling');
            },
            stop: function(e, ui) {
                $('.menu-container').removeClass('stop-scrolling');
            }
        }).draggable('enable').addClass('draggable');
        $(self).trigger(event)
    }, 800);
});

$(document).on("touchend", function () {
    clearTimeout(t);
    $('.draggable:not(.ui-draggable-helper)').draggable( 'disable' ).removeClass('draggable');
});
4

1 回答 1

3

我遇到了同样的问题,我通过在以下位置添加 if 语句来解决它jquery.ui.touch-punch.js

这是原始代码(从第 31 行开始):

function simulateMouseEvent (event, simulatedType) {

  // Ignore multi-touch events
  if (event.originalEvent.touches.length > 1) {
    return;
  }

  event.preventDefault();

这是更新的代码:

function simulateMouseEvent (event, simulatedType) {

  // Ignore multi-touch events
  if (event.originalEvent.touches.length > 1) {
    return;
  }

  if(event.cancelable) {
    event.preventDefault();
  }
于 2018-11-27T08:38:37.463 回答