我想获取当前鼠标位置,但不想使用:
$(document).bind('mousemove',function(e){
$("#log").text("e.pageX: " + e.pageX + ", e.pageY: " + e.pageY);
});
because I just need to get the position and process the information
我想获取当前鼠标位置,但不想使用:
$(document).bind('mousemove',function(e){
$("#log").text("e.pageX: " + e.pageX + ", e.pageY: " + e.pageY);
});
because I just need to get the position and process the information
I don't believe there's a way to query the mouse position, but you can use a mousemove
handler that just stores the information away, so you can query the stored information.
jQuery(function($) {
var currentMousePos = { x: -1, y: -1 };
$(document).mousemove(function(event) {
currentMousePos.x = event.pageX;
currentMousePos.y = event.pageY;
});
// ELSEWHERE, your code that needs to know the mouse position without an event
if (currentMousePos.x < 10) {
// ....
}
});
But除了setTimeout
个代码之类的代码外,几乎所有代码都是响应事件运行的,大多数事件都提供鼠标位置.所以你需要知道鼠标在哪里的代码可能已经可以访问这些信息了...