ChatGPT解决这个技术问题 Extra ChatGPT

jquery-ui 可排序 |如何让它在 iPad/触摸设备上工作?

如何让 jQuery-UI 可排序功能在 iPad 和其他触控设备上运行?

http://jqueryui.com/demos/sortable/

我尝试将 event.preventDefault();event.cancelBubble=true;event.stopPropagation();touchmovescroll 事件一起使用,但结果是页面不再滚动。

有任何想法吗?

有错误报告吗?

B
Brandon C

找到了一个解决方案(直到现在只用 iPad 测试过!)!

https://github.com/furf/jquery-ui-touch-punch


这也适用于 Android 平板电脑。在 Android 3.1 上的三星 Galaxy tab 10.1 上进行了专门测试。
适用于搭载 Android 2.3.4 的三星 Galaxy S2
适用于搭载 Android 4.1.2 的三星 Galaxy S2
这很好用!虽然我有一个覆盖整个页面的表格,所以在不移动元素的情况下很难上下滚动。有没有人解决这个问题?添加一些东西来防止元素移动,直到它们在 X 秒内接触到特定的元素应该可以解决问题?
自 1/2014 起,它不能在 Windows Phone 的 Internet Explorer 上运行。希望当其他浏览器可用时,这将起作用。
v
vpibano

使 sortable 在移动设备上工作。我像这样使用 touch-punch

$("#target").sortable({
  // option: 'value1',
  // otherOption: 'value2',
});

$("#target").disableSelection();

请注意在创建可排序实例后添加 disableSelection();


这对我不起作用,但对投票无效。
A
Abdulrazak Zakieh

@eventhorizon 提供的解决方案 100% 有效。但是,当您在手机上启用它时,在大多数情况下您会遇到滚动问题,而在我的情况下,我的手风琴由于不可点击而停止工作。解决它的一种解决方法是使拖动可通过图标初始化,例如,然后使其可排序使用它来初始化拖动,如下所示:

$("#sortableDivId").sortable({
        handle: ".ui-icon"
});

您在其中传递您想要作为初始化程序的类名。


T
Tunaki

Tom,我在 mouseProto._touchStart 事件中添加了以下代码:

var time1Sec;
var ifProceed = false, timerStart = false;
mouseProto._touchStart = function (event) {

    var self = this;

    // Ignore the event if another widget is already being handled
    if (touchHandled || !self._mouseCapture(event.originalEvent.changedTouches[0])) {
        return;
    }

    if (!timerStart) {
        time1Sec = setTimeout(function () {
            ifProceed = true;
        }, 1000);
        timerStart=true;
    }
    if (ifProceed) {
        // Set the flag to prevent other widgets from inheriting the touch event
        touchHandled = true;

        // Track movement to determine if interaction was a click
        self._touchMoved = false;

        // Simulate the mouseover event
        simulateMouseEvent(event, 'mouseover');

        // Simulate the mousemove event
        simulateMouseEvent(event, 'mousemove');

        // Simulate the mousedown event
        simulateMouseEvent(event, 'mousedown');
        ifProceed = false;
         timerStart=false;
        clearTimeout(time1Sec);
    }
};

C
Cardi DeMonaco Jr

票数最高的答案的链接现已断开。

要让 jQuery UI Sortable 在移动设备上工作:

将此 JavaScript 文件添加到您的项目中。在您的页面上引用该 JS 文件。

如需更多信息,check out this link


关注公众号,不定期副业成功案例分享
关注公众号

不定期副业成功案例分享

领先一步获取最新的外包任务吗?

立即订阅