2017-08-19 4 views
1

を見つけることができません:は、私は私のコードベースでこの機能を持っているイベント定義に

let touch = true; 

function init() { 
    let firstMousemoveHasOccured = false; 
    $(window).on('mousemove.touchdetection',() => { 
     if (firstMousemoveHasOccured) { 
      touch = false; 
      $(window).off('mousemove.touchdetection touchend.touchdetection'); 
     } else { 
      firstMousemoveHasOccured = true; 
     } 
    }); 
    $(window).on('touchend.touchdetection',() => { 
     touch = true; 
     $(window).off('mousemove.touchdetection touchend.touchdetection'); 
    }); 
} 

イベントmousemove.touchdetectionは、標準のイベントではありませんので、これはどこから来ていますか?

答えて

2

これらは、イベント名mousemoveの最初の部分は、呼び出しコールバックを解雇し、イベントでjQuery namespaced events

です。 2番目の部分touchdetectionは、特定のクラスまたはグループのmousemoveイベントを簡単に無効にすることができるという点を除いて、意味がありません。あなたはAPIドキュメントを読んでから見るよう

$(document).off('mousemove'); //turns off all callbacks attached to the `mousemove` event. 
$(document).off('mousemove.touchdetection'); //turns of all callbacks attached to the mousemove event that have been attached with the touchdetection namespace 

この目的は、あなたが簡単にサードパーティのコードによって取り付けられたリスナーに影響を与えることなく、アプリケーションの中で、あなたのリスナーを変更できるようにすることです。

+0

伝説 - ありがとう:) – JoeTidee

関連する問題