How to obtain mousewheel information and mouse position together in jquery/javascript
-
28-04-2021 - |
문제
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.
제휴하지 않습니다 StackOverflow