无法找到事件定义

时间:2017-08-19 22:12:52

标签: javascript jquery events

我的代码库中有这个功能:

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不是标准事件,所以它来自何处?

1 个答案:

答案 0 :(得分:2)

这些是jQuery namespaced events

事件名称mousemove的第一部分是在被触发时调用回调的事件。第二部分touchdetection没有意义,除了它允许您轻松地关闭特定类别或一组mousemove事件。

$(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

正如您从阅读API文档中看到的那样,目的是允许您轻松修改应用程序中的侦听器,而不会影响第三方代码附加的侦听器。