HTML Drag And Drop On Mobile Devices

后端 未结 8 1011
栀梦
栀梦 2020-11-29 16:28

When you add drag and drop to a web page using JavaScript, such as jQuery UI draggable and droppable, how do you get this to work when viewed via a browser on a mobile devic

8条回答
  •  鱼传尺愫
    2020-11-29 16:37

    Jquery Touch Punch is great but what it also does is disable all the controls on the draggable div so to prevent this you have to alter the lines... (at the time of writing - line 75)

    change

    if (touchHandled || !self._mouseCapture(event.originalEvent.changedTouches[0])){
    

    to read

    if (touchHandled || !self._mouseCapture(event.originalEvent.changedTouches[0]) || event.originalEvent.target.localName === 'textarea'
            || event.originalEvent.target.localName === 'input' || event.originalEvent.target.localName === 'button' || event.originalEvent.target.localName === 'li'
            || event.originalEvent.target.localName === 'a'
            || event.originalEvent.target.localName === 'select' || event.originalEvent.target.localName === 'img') {
    

    add as many ors as you want for each of the elements you want to 'unlock'

    Hope that helps someone

提交回复
热议问题