回答

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