jquery-ui sortable | How to get it work on iPad/touchdevices?

后端 未结 4 1557
遥遥无期
遥遥无期 2020-12-22 17:11

How do I get the jQuery-UI sortable feature working on iPad and other touch devices?

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

I tried to using event.prevent

相关标签:
4条回答
  • 2020-12-22 17:16

    The link for the top-voted Answer is now broken.

    To get jQuery UI Sortable working on mobile:

    1. Add this JavaScript file to your project.
    2. Reference that JS file on your page.

    For more information, check out this link.

    0 讨论(0)
  • 2020-12-22 17:20

    Found a solution (only tested with iPad until now!)!

    http://touchpunch.furf.com/content.php?/sortable/default-functionality

    0 讨论(0)
  • 2020-12-22 17:34

    To make sortable work on mobile. Im using touch-punch like this:

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

    Take note of adding disableSelection(); after creating the sortable instance.

    0 讨论(0)
  • 2020-12-22 17:40

    Tom, I have added following code to mouseProto._touchStart event:

    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);
        }
    };
    
    0 讨论(0)
提交回复
热议问题