I am using JQuery mousewheel downloaded from https://github.com/brandonaaron/jquery-mousewheel/downloads to obtain mousewheel information. At the same, I want to obtain the position of the mouse when the wheel was rolled. How can I achieve this ?

My current function is as below:

$(function() {
    $('#maindiv').mousewheel(function(event, delta, deltaX, deltaY) {   
    // somehow obtain mouse position
        // Use delta and mouse position for a purpose
    });
});
有帮助吗?

解决方案

You should be able to access the jQuery default behaviour of any event, that allows you to read the event.pageX and event.pageY.

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

Take a look at the jQuery-Event for Details.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top