多个 jQuery.on() 事件在 xBrowser 中不起作用(取决于顺序)

Multiple jQuery .on() events not working xBrowser (dependent on order)

我正在使用 "DOMMouseScroll" 事件代替鼠标滚轮以支持 Firefox。我不确定为什么会出现以下行为:

以下将允许 DOMMouseScroll 在 Firefox 中工作,但我的滚动或鼠标滚轮事件不会触发。

$contents.on 'scroll, mousewheel, DOMMouseScroll', @handleScroll

但是当我分离绑定时,在 Chrome 和 Firefox 中一切正常。

$contents.on 'scroll, mousewheel', @handleScroll
$contents.on 'DOMMouseScroll', @handleScroll

如果我重新排序以下内容,我会 chrome 再次工作,但不是 firefox:

$contents.on 'scroll, DOMMouseScroll, mousewheel', @handleScroll

很明显,顺序很重要,鼠标滚轮是最后一个绑定,因此它在 DDOMMouseScroll 上工作,将它们分开是解决方案。我只想知道为什么。

当我查看 the jQuery source for .on() 时,我看到:

function (types, selector, data, fn, one) {
    var type, origFn;

    if (typeof types === "object") {
        if (typeof selector !== "string") {
            data = data || selector;
            selector = undefined;
        }
        for (type in types) {
            this.on(type, selector, data, types[type], one);
        }
        return this;
    }

type-in​​-types 循环不应该提供与创建单独的个人绑定相同的效果吗?

on 方法中不应该有逗号:

$contents.on 'scroll mousewheel DOMMouseScroll', @handleScroll

在您的情况下,jQuery 正在侦听 scroll,DOMMouseScroll, 等事件。

jQuery 文档:https://api.jquery.com/on/