触发焦点/模糊事件时获取鼠标位置? [英] Get mouse position when focus/blur events are fired?
本文介绍了触发焦点/模糊事件时获取鼠标位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用jQuery捕获事件:
I'm using jQuery to capture an event:
$('input').focus(function(e){
console.log( e.pageX, e.pageY );
});
这似乎不起作用...关于获取鼠标位置的其他方法的任何想法?
This doesn't seem to work... any ideas on alternative ways to getting the mouse position?
帮助会很棒.
推荐答案
您只能使用鼠标事件获取鼠标坐标.如果要捕获鼠标的位置,则可以使用全局 mousemove
事件侦听器,并将坐标存储在一组变量中,以后可以通过 focus 进行访问代码>功能.示例:
You can only get mouse coordinates using mouse events. If you want to capture the position of the mouse, you can use a global mousemove
event listener, and store the coordinates in a set of variables, which can later be accessed by the focus
function. Example:
var pageX, pageY; //Declare these globally
$(window).mousemove(function(e){
pagex = e.pageX;
pageY = e.pageY;
});
$('input').focus(function(){
console.log(pageX, pageY); // These variables have been defined by the global
// mousemove event
});
这篇关于触发焦点/模糊事件时获取鼠标位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文