回答

2

我自己修复了它。这与将鼠标事件映射为触摸事件一样简单。

因此,解决办法是寻找&替换:

mousedown -> touchstart 
mouseup -> touchend 
mousemove -> touchmove 
10

这里是我的解决方案,使MooTools的拖放支持触摸事件。这种方法并不需要我来编辑MooTools的多个文件,因为我用Class.refactor(这仅通过MooTools V.1.3.1测试) - 它也不会打破通常的单击事件

Class.refactor(Drag, 
    { 
     attach: function(){ 
      this.handles.addEvent('touchstart', this.bound.start); 
      return this.previous.apply(this, arguments); 
     }, 

     detach: function(){ 
      this.handles.removeEvent('touchstart', this.bound.start); 
      return this.previous.apply(this, arguments); 
     }, 

     start: function(event){ 
      document.body.addEvents({ 
       touchmove: this.bound.check, 
       touchend: this.bound.cancel 
      }); 
      this.previous.apply(this, arguments); 
     }, 

     check: function(event){ 
      if (this.options.preventDefault) event.preventDefault(); 
      var distance = Math.round(Math.sqrt(Math.pow(event.page.x - this.mouse.start.x, 2) + Math.pow(event.page.y - this.mouse.start.y, 2))); 
      if (distance > this.options.snap){ 
       this.cancel(); 
       this.document.addEvents({ 
        mousemove: this.bound.drag, 
        mouseup: this.bound.stop 
       }); 
       document.body.addEvents({ 
        touchmove: this.bound.drag, 
        touchend: this.bound.stop 
       }); 
       this.fireEvent('start', [this.element, event]).fireEvent('snap', this.element); 
      } 
     }, 

     cancel: function(event){ 
      document.body.removeEvents({ 
       touchmove: this.bound.check, 
       touchend: this.bound.cancel 
      }); 
      return this.previous.apply(this, arguments); 
     }, 

     stop: function(event){ 
      document.body.removeEvents({ 
       touchmove: this.bound.drag, 
       touchend: this.bound.stop 
      }); 
      return this.previous.apply(this, arguments); 
     } 
    }); 
+0

awesome,+1 - 如果这已经在生产环境中测试过并且可行,那么为什么不修改原始类并向mootools发送拉请求 - 更多呢?触摸设备更为广泛,这对于开箱即用非常有用。 –

+0

太棒了!你知道如何在触摸事件拖动时禁用滚动吗?我的窗口在拖动时同时滚动... – Sergio

+0

实际上,由于Android错误,存在问题,请参阅http://uihacker.blogspot.it/2011/01/android-touchmove-event-bug.html和http :?//code.google.com/p/android/issues/detail ID = 5491。基本上你需要在touchmove回调中调用event.preventDefault(),然后调整事件以正确地移除事件处理程序 – abidibo