如何在jquery/javascript中一起获取鼠标滚轮信息和鼠标位置

ali*_*buz 1 jquery mousewheel mouse-position

我正在使用从https://github.com/brandonaaron/jquery-mousewheel/downloads下载的JQuery鼠标滚轮来获取鼠标滚轮信息.同时,我想在滚轮时获得鼠标的位置.我怎样才能做到这一点?

我目前的功能如下:

$(function() {
    $('#maindiv').mousewheel(function(event, delta, deltaX, deltaY) {   
    // somehow obtain mouse position
        // Use delta and mouse position for a purpose
    });
});
Run Code Online (Sandbox Code Playgroud)

Tha*_*bas 6

您应该能够访问任何事件的jQuery默认行为,允许您阅读event.pageXevent.pageY.

$(function() {
    $('#maindiv').mousewheel(function(event, delta, deltaX, deltaY) {   
        var mousePosition = { x: event.pageX, y: event.pageY };
        // ...
    });
});
Run Code Online (Sandbox Code Playgroud)

看一下jQuery-Event for Details.