Jquery 绑定鼠标滚轮返回未定义的值

Jquery 绑定鼠标滚轮返回未定义的值,jquery,Jquery,我正在测试以下代码: $(window).bind('mousewheel', function(e) { alert(e.wheelDelta); }); 每次我移动鼠标weel,都会得到“未定义”。当我试图捕获鼠标滚轮并基于它移动div时,有人能帮我吗?我想你需要做更多的工作才能让它在所有浏览器中正常工作,或者试试 如果扩展仍然不能正常工作,您可以尝试我刚才创建的这个修改版本: /* jquery.mousewheel.min.js * Copyright (c) 2009 Bran

我正在测试以下代码:

$(window).bind('mousewheel', function(e) {
  alert(e.wheelDelta);
});

每次我移动鼠标weel,都会得到“未定义”。当我试图捕获鼠标滚轮并基于它移动div时,有人能帮我吗?

我想你需要做更多的工作才能让它在所有浏览器中正常工作,或者试试

如果扩展仍然不能正常工作,您可以尝试我刚才创建的这个修改版本:

/* jquery.mousewheel.min.js
 * Copyright (c) 2009 Brandon Aaron (http://brandonaaron.net)
 * Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php)
 * and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
 * Thanks to: http://adomas.org/javascript-mouse-wheel/ for some pointers.
 * Thanks to: Mathias Bank(http://www.mathias-bank.de) for a scope bug fix.
 *
 * Version: 3.0.2
 * 
 * Requires: 1.2.2+
 */
(function(c) {
    var a = [ "DOMMouseScroll", "mousewheel" ];
    c.event.special.mousewheel = {
        setup : function() {
            if (this.addEventListener) {
                for ( var d = a.length; d;) {
                    this.addEventListener(a[--d], b, false)
                }
            } else {
                this.onmousewheel = b
            }
        },
        teardown : function() {
            if (this.removeEventListener) {
                for ( var d = a.length; d;) {
                    this.removeEventListener(a[--d], b, false)
                }
            } else {
                this.onmousewheel = null
            }
        }
    };
    c.fn.extend({
        mousewheel : function(d) {
            return d ? this.bind("mousewheel", d) : this.trigger("mousewheel")
        },
        unmousewheel : function(d) {
            return this.unbind("mousewheel", d)
        }
    });
    function b(f) {
        var d = [].slice.call(arguments, 1), g = 0, e = true;
        if (f.wheelDelta) {
            g = f.wheelDelta / 120
        }
        if (f.detail) {
            g = -f.detail / 3
        }
        // I had to move the following two lines down, probably because of jQuery update
        f = c.event.fix(f || window.event);
        f.type = "mousewheel";
        f.pageX = f.originalEvent.pageX;
        f.pageY = f.originalEvent.pageY;
        d.unshift(f, g);
        return c.event.handle.apply(this, d)
    }
})(jQuery);
我刚刚在Firefox和Chrome上测试了它,但我不知道它在其他浏览器上是否有效。用法:

$('element').mousewheel(function(e, delta) { alert(delta); });

我最终使用了以下代码段:

jQuery(function($) {
$(document)
        .bind('mousewheel', function(event, delta) {
        if(delta > 0) {
                    // Scrolling down
        } else {
                    // Scrolling up
        }
    });
});

这需要jquery鼠标轮扩展,并在IE、Firefox和Chrome中工作。

我也有同样的问题,解决方案是将jquery版本从1.7.x更改为1.9.x

在绑定函数中尝试
console.log(e)
。这将向您显示它所拥有的属性。
$(窗口).bind('mousewheel',函数(event,delta,deltaY,deltaX){alert(delta);})我添加了这个扩展并测试了以下代码(在Chrome中)。我得到了同样的数据。Firefox似乎根本没有检测到它。
e.originalEvent.wheelDelta
似乎在Chrome中返回了我想要的数据。IE和Firefox似乎没有响应(甚至都没有触发事件)。哦,我记得我使用它时有一些bug需要修复。请参阅上面的代码,它对我有效。